1. Checking the Current Deployments
Assuming a running Kubernetes cluster with two applications deployed (“red” and “blue”), first confirm that the deployments exist:2. Verifying the ETCD Version and Pod Details
To identify the version of etcd and verify pod details, locate the etcd pod in the kube-system namespace. Typically configured as a static pod, you can review its description to inspect container details and command-line parameters. For example, examining the etcd container shows:- Server certificate:
/etc/kubernetes/pki/etcd/server.crt - CA certificate:
/etc/kubernetes/pki/etcd/ca.crt
3. Preparing for Maintenance
When maintenance, such as a master node reboot, is scheduled, it is best practice to back up the etcd data. Using the built-in snapshot functionality ensures that your Kubernetes cluster data can be restored if needed. Review the static pod definition fragment in/etc/kubernetes/manifests/etcd.yaml. Notice the configuration for volume mounts and probes:
The use of hostPath volumes maps the control plane node’s physical directories for data and certificates directly into the etcd container.
4. Taking an ETCD Snapshot
Before initiating maintenance, take an etcd snapshot for backup. Ensure that the etcdctl API version is set to 3. The snapshot command requires specifying the endpoint along with the proper certificates. Run the following command to create a snapshot:5. Post-Maintenance Issue Identification
After the maintenance (for example, following a reboot), you may notice that the cluster applications are inaccessible. Confirm the current state by checking the deployments, pods, and services:6. Restoring ETCD from Backup
To restore etcd from the snapshot, use the etcdctl snapshot restore command. This process does not require contacting an active etcd endpoint; it restores the data from the backup file into a new data directory. For example, run:7. Reconfiguring the ETCD Pod
After restoring the etcd data, update the etcd static pod manifest (located at/etc/kubernetes/manifests/etcd.yaml) to point to the new data directory. Modify the hostPath for the etcd-data volume from /var/lib/etcd to /var/lib/etcd-from-backup.
The updated volume section should look like:
If the new etcd pod fails to reach the Running state, such as due to failed liveness or startup probes, consider manually deleting the pod to force a restart.
With the etcd backup successfully restored and the static pod manifest updated, your Kubernetes control plane resumes normal operations and the applications become accessible again. This completes the backup and restore process for etcd in a Kubernetes cluster.