Back Up and Restore etcd on a kubeadm Cluster
Goal
Take scheduled etcd snapshots on a kubeadm control plane, keep them on the node, on a NAS and on a workstation, prove they restore without touching the live cluster, and know the steps of a real restore. This is the manual version of what playbook 10-etcd-backup.yaml does in my homelab repo.
Prerequisites
- A kubeadm control plane with stacked etcd (the static pod in
/etc/kubernetes/manifests/etcd.yaml). - An NFS share for backups: a dedicated dataset, exported only to the control-plane IPs, with root mapped to root so a root job can write (see Provide NFS Storage to Kubernetes).
nfs-common,zstdandtaron the node.
Steps
Install etcdctl and etcdutl at the Running Version
kubeadm runs etcd from an image, so the node has no etcd tools. Use the release that matches the image tag:
grep 'image:' /etc/kubernetes/manifests/etcd.yaml # e.g. registry.k8s.io/etcd:3.6.8-0 -> 3.6.8
V=3.6.8
cd /tmp && curl -LO https://github.com/etcd-io/etcd/releases/download/v$V/etcd-v$V-linux-amd64.tar.gz
curl -LO https://github.com/etcd-io/etcd/releases/download/v$V/SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS # must print OK
sudo mkdir -p /opt/etcd-v$V && sudo tar -xzf etcd-v$V-linux-amd64.tar.gz -C /opt/etcd-v$V --strip-components=1
sudo ln -sfn /opt/etcd-v$V /opt/etcd
sudo ln -sf /opt/etcd/etcdctl /opt/etcd/etcdutl /usr/local/bin/
The etcd server binary stays out of PATH: only the restore drill uses it.
Take a Snapshot and Bundle It with the PKI
- Snapshot through the local member with the read-only
healthcheck-clientcertificate kubeadm creates:P=/etc/kubernetes/pki/etcd sudo etcdctl --endpoints=https://127.0.0.1:2379 --cacert=$P/ca.crt \ --cert=$P/healthcheck-client.crt --key=$P/healthcheck-client.key snapshot save /tmp/snapshot.db sudo etcdutl snapshot status /tmp/snapshot.db -w table # hash, revision, total keys - Bundle the snapshot with
/etc/kubernetes/pkiand the manifests: a restore on a rebuilt node needs the CA keys too (see An etcd Snapshot Alone Can't Rebuild a kubeadm Control Plane, So Back Up the PKI with It). Keep it root-only:(umask 077; sudo tar --zstd -cf etcd-$(hostname -s)-$(date -u +%Y%m%dT%H%M%SZ).tar.zst \ -C /tmp snapshot.db -C / etc/kubernetes/pki etc/kubernetes/manifests) - Write a
.sha256next to each bundle and check it again after copying it anywhere.
Mount the NAS Only When Needed
A systemd automount, with soft NFS options, so a NAS outage makes the copy fail instead of hanging boot or the job. The unit name must match the path (/mnt/backups → mnt-backups):
# /etc/systemd/system/mnt-backups.mount
[Mount]
What=<nas>:/mnt/<pool>/backups
Where=/mnt/backups
Type=nfs
Options=soft,timeo=100,retrans=3,noatime,_netdev
# /etc/systemd/system/mnt-backups.automount
[Automount]
Where=/mnt/backups
TimeoutIdleSec=600
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now mnt-backups.automount
Schedule It
Put the snapshot, bundle, copy and pruning in one script (/usr/local/sbin/etcd-backup): write locally first, copy to the NAS under a temporary name, rename, re-check the checksum there, keep the newest N in each place. Exit with a distinct status when only the NAS copy failed. Then a oneshot service and a timer:
# /etc/systemd/system/etcd-backup.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/etcd-backup
Nice=10
IOSchedulingClass=idle
# /etc/systemd/system/etcd-backup.timer
[Timer]
OnCalendar=*-*-* 00/6:00:00
RandomizedDelaySec=15min
Persistent=true
[Install]
WantedBy=timers.target
Persistent=true runs a missed backup at the next boot. Keep a third copy off the NAS (a workstation pulling over SSH) until the pool is mirrored.
Prove It: Restore Drill
Restore the bundle into a throwaway etcd on loopback, read it, compare it with the live one. The live etcd is only read:
D=$(sudo mktemp -d) && sudo tar --zstd -xf <bundle> -C $D
sudo etcdutl snapshot restore $D/snapshot.db --data-dir $D/data --name drill \
--initial-cluster drill=http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380
sudo /opt/etcd/etcd --name drill --data-dir $D/data \
--listen-client-urls http://127.0.0.1:12379 --advertise-client-urls http://127.0.0.1:12379 \
--listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 \
--initial-cluster drill=http://127.0.0.1:12380 &
etcdctl --endpoints=http://127.0.0.1:12379 get /registry/namespaces/ --prefix --keys-only
# stop it (kill %1) and remove $D
Run it monthly and after every etcd upgrade.
Restore for Real (One Control Plane)
Everything written after the snapshot is lost.
- Move
kube-apiserver.yamlandetcd.yamlout of/etc/kubernetes/manifests; the kubelet stops both pods. Wait untilcrictl psno longer lists them. - Move
/var/lib/etcdaside, then restore with the member name and peer URL from the bundledetcd.yaml:
The two last flags keep revisions moving forward and end every watch, so controllers re-list instead of trusting caches newer than the snapshot.sudo etcdutl snapshot restore snapshot.db --data-dir /var/lib/etcd \ --name <node> --initial-cluster <node>=https://<node-ip>:2380 \ --initial-advertise-peer-urls https://<node-ip>:2380 \ --bump-revision 1000000000 --mark-compacted - Put the manifests back, check
kubectl get nodesandget pods -A, then restart the CNI agents, CoreDNS and any controller that misbehaves.
On a rebuilt machine, restore /etc/kubernetes/pki from the bundle before kubeadm init, with the same hostname and IP. With several control planes, stop all of them and restore the same snapshot on each, with its own name and the full --initial-cluster list.
Verify
-
systemctl list-timers etcd-backup.timershows the next run. -
journalctl -u etcd-backup.serviceshows the key count, the local file and the NAS copy with a matching checksum. - A copy exists off the NAS, with a checked sha256.
- The restore drill passes, with key counts close to the live ones (events and leases change between the two).
Troubleshooting
- The local copy works, the NAS copy doesn't, and
mnt-backups.mountis failed: the share isn't exported to this node (showmount -e <nas>), or root is squashed. Fix the share, thensudo systemctl reset-failed mnt-backups.mountbefore retrying. journalctl -u etcd-backup.serviceprints-- No entries --: a regular user only sees their own journal. Usesudo.etcdctlgetsx509: certificate signed by unknown authority: the etcd CA (pki/etcd/ca.crt) is a different CA from the cluster's (pki/ca.crt). Use the etcd one.
References
- etcd documentation: Disaster recovery - snapshot, restore, and the revision bump for clients with watch caches such as Kubernetes (last checked 2026-11).
- Kubernetes documentation: Operating etcd clusters for Kubernetes - backing up and restoring the cluster's etcd (last checked 2026-11).
- systemd.timer and systemd.automount -
Persistent=,RandomizedDelaySec=,TimeoutIdleSec=. - An etcd Snapshot Alone Can't Rebuild a kubeadm Control Plane, So Back Up the PKI with It - why the bundle carries the PKI.
- An etcd Snapshot Rolls the Whole Cluster Back, So Restore Only When Re-Applying Can't Fix It - when to restore and when to re-apply instead.
- A Checksum Proves a Copy Is Identical, Not That the Backup Restores - what the
.sha256checks prove. - Homelab v2 Rebuild - where this was set up (2026-11-23).
homelab/docs/runbooks/etcd-backup-and-restore.md- the runbook for my cluster.- Kubernetes MOC - hub for Kubernetes notes.