CKA · 5 November 2026 · 6 min read
etcd backup and restore in Kubernetes, step by step
How to restore etcd from a snapshot on a kubeadm cluster: take the snapshot with etcdctl, check it and restore it with etcdutl, point the etcd static Pod at the restored data, and fix it when etcd does not come back.
To restore etcd on a kubeadm cluster, run etcdutl snapshot restore to unpack the snapshot into a new data directory, then change the etcd-data hostPath in /etc/kubernetes/manifests/etcd.yaml to that directory; the kubelet restarts etcd from the restored data. The backup itself is an etcdctl snapshot save with the certificates from the same manifest. etcd holds the whole state of the cluster, every Deployment, Secret and RBAC rule, so this is a core administration task and a long-standing part of the CKA.
TL;DR
- Back up:
etcdctl snapshot savewith--endpoints,--cacert,--certand--keyread from/etc/kubernetes/manifests/etcd.yaml. - Check:
etcdutl snapshot status <file> -w table. - Restore:
etcdutl snapshot restore <file> --data-dir /var/lib/etcd-restore, always into a new directory. - Point the
etcd-datahostPathin the etcd manifest at the new directory and wait for the kubelet to restart etcd. - Exam: CKA Cluster Architecture, Installation and Configuration (25%). Not on the CKAD.
This article walks through a backup and restore on a kubeadm cluster with a single control plane node, where etcd runs as a static Pod. Every step uses commands you can type on the control plane node.
Two tools: etcdctl and etcdutl
etcd ships two command-line tools, and it matters which one you use:
etcdctltalks to a running etcd server over the network. You use it to take a snapshot.etcdutlworks directly on files on disk, with no server involved. You use it to inspect and restore a snapshot.
Older guides use etcdctl snapshot restore and etcdctl snapshot status. Those subcommands are deprecated in favor of etcdutl, and may be missing from newer etcd releases. Check what you have with:
etcdctl versionetcdutl versionOlder guides also set ETCDCTL_API=3. Version 3 has been the default API for a long time, so it is no longer needed, but it does no harm.
Find the connection details
etcd on a kubeadm cluster only accepts TLS connections from clients with a valid certificate. You need four values: the endpoint, the CA certificate, a client certificate and its key. Do not guess them. Read them from the etcd static Pod manifest:
sudo grep -E 'listen-client-urls|trusted-ca-file|cert-file|key-file|data-dir' \ /etc/kubernetes/manifests/etcd.yamlOn a default kubeadm install you will see lines like these (paths may differ on your cluster, which is exactly why you read them from the file):
- --cert-file=/etc/kubernetes/pki/etcd/server.crt - --data-dir=/var/lib/etcd - --key-file=/etc/kubernetes/pki/etcd/server.key - --listen-client-urls=https://127.0.0.1:2379,https://192.168.1.10:2379 - --trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crtThe pattern also matches the --peer-cert-file and --peer-key-file lines. Ignore those; they are for traffic between etcd members. Use the ones without peer.
Take the snapshot
Map the values from the manifest to etcdctl flags: the client URL to --endpoints, --trusted-ca-file to --cacert, --cert-file to --cert and --key-file to --key.
sudo etcdctl \ --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key \ snapshot save /opt/backup/etcd-snapshot.dbMake sure the target directory exists first. The certificate files are readable only by root, which is why the command runs with sudo. If the command hangs or fails with a certificate error, one of the four values is wrong; go back to the manifest.
It is good practice to check that etcd is reachable with the same flags before relying on them:
sudo etcdctl --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key \ endpoint healthCheck the snapshot
A snapshot file you have never inspected is not a backup you can trust. Use etcdutl to read it:
sudo etcdutl snapshot status /opt/backup/etcd-snapshot.db -w tableThis prints the hash, revision, total number of keys and size. A key count of zero, or an error, means something went wrong. On older installations without etcdutl, etcdctl snapshot status gives the same information.
Restore the snapshot
Restoring does not write into the existing data directory. It creates a new data directory from the snapshot, and you then point etcd at it.
First, restore to a directory that does not exist yet:
sudo etcdutl snapshot restore /opt/backup/etcd-snapshot.db \ --data-dir /var/lib/etcd-restoreOn a single-member cluster that is all you need. Restoring a multi-member cluster also needs --name, --initial-cluster and related flags on each member; the etcd documentation covers that case.
Next, tell the etcd static Pod to use the new directory. Edit the manifest:
sudo vim /etc/kubernetes/manifests/etcd.yamlNear the bottom, find the hostPath volume that holds etcd's data and change its path:
volumes: - hostPath: path: /var/lib/etcd-restore type: DirectoryOrCreate name: etcd-dataChanging only the hostPath is the smallest edit. The container still sees its data at /var/lib/etcd, so --data-dir and the volumeMounts entry stay as they are. If you prefer to change --data-dir as well, then the mountPath must change to match, or etcd will start with an empty directory.
Save the file. The kubelet watches /etc/kubernetes/manifests and recreates the etcd Pod when the manifest changes. This takes a minute or so, and the API server will be unavailable while etcd restarts, so kubectl commands may fail for a while. Watch the containers directly with the container runtime:
sudo crictl ps | grep -E 'etcd|kube-apiserver'When both are running, check that the cluster is back and that the restored objects are there:
kubectl get nodeskubectl get deploy -AAnything created after the snapshot was taken will be gone. That is expected: the cluster is now exactly as it was at the time of the snapshot.
If etcd does not come back after the restore
The API server depends on etcd, so while etcd is down kubectl answers with connection refused or times out. Work from the control plane node with the container runtime instead:
sudo crictl ps -a | grep etcdsudo crictl logs <etcd-container-id>sudo journalctl -u kubelet --since "10 min ago" | grep -i etcd- No etcd container at all: the manifest probably has a YAML error, so the kubelet cannot read it. The kubelet log says which line. Fix the indentation and save again.
- etcd starts, but the cluster looks empty: etcd is reading an empty directory. The
hostPath, thevolumeMountsmountPathand--data-dirdo not line up. - etcd exits with a permission or "member" error: make sure you restored into a directory that did not exist before, and that you did not restore twice into the same path. Remove the directory and restore again.
- Everything is running but kubectl still fails: give it a minute. The API server restarts once etcd is healthy, and its own static Pod may take a while to settle.
Common mistakes
- Restoring into the existing
/var/lib/etcddirectory. Restore to a new directory and switch to it. - Editing the manifest on the wrong node. etcd runs on the control plane node, so the restore and the edit happen there.
- Changing
--data-dirbut not the volume, or the volume but not the mount, so etcd starts empty. - Leaving a backup copy of the manifest inside
/etc/kubernetes/manifests. The kubelet treats every file there as a Pod. Keep copies elsewhere.
The Operating etcd clusters for Kubernetes page on kubernetes.io covers backup and restore in more depth.
Keep going
A backup and restore is something to do with your own hands several times before the exam, on a cluster you are allowed to break. The Gazeek CKA course gives you a real cluster for each lab, with guided tasks and checks. The free practice questions in the Gazeek Memory Gym help you remember which flag maps to which file.