Skip to main content
In this lesson, you will learn how to back up and restore an etcd cluster running on a Kubernetes control plane. We begin by verifying the existing deployments, inspecting the etcd container setup, and then proceed with the backup and restore procedures.

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:
From the information provided, the etcd version is 3.5.1 running on port 2379 (loopback address). The container’s command-line options also specify critical certificate file locations:
  • Server certificate: /etc/kubernetes/pki/etcd/server.crt
  • CA certificate: /etc/kubernetes/pki/etcd/ca.crt
A similar configuration is confirmed in the second block:

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.
Verify these paths to confirm the etcd data and certificates exist on the host:

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:
Verify the backup has been saved:

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:
Since deployments and services are missing, you need to restore the etcd data from your backup.

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:
Confirm that the new directory (/var/lib/etcd-from-backup) contains the restored data.

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:
Once you update and save the changes, the kubelet will automatically restart the etcd pod with the updated manifest configuration. Monitor the pod’s status to ensure it transitions to the Running state:
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.
Finally, verify the restored state of the cluster by checking that deployments, pods, and services are now available:

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.

Watch Video

Practice Lab