Sub topic 7
Restoring a multi-member etcd cluster
This chapter assumes you can take and verify a snapshot, and that you have restored etcd on a single control plane node. You also need SSH access to every control plane node.
Why multi-member restore is different
A highly available (HA) cluster usually runs three or five etcd members. Each member stores its own copy of the data and a list of the other members. If you restore only one member from a snapshot, it carries a different history from the others. The members will not agree, and the cluster may refuse to start.
The rule is that every member is restored from the same snapshot file. Each restore creates a new cluster. The old membership information is discarded and replaced with the list you provide.
The restore sequence
placeholderFollow these steps in order.
- Stop the API server and etcd on every control plane node. On a kubeadm cluster, move the static Pod manifests out of
/etc/kubernetes/manifests. The kubelet stops the Pods when the files disappear. - Copy the same snapshot file to every control plane node.
- Run
etcdutl snapshot restoreon each node. Give each member its own name and peer URL, and the same cluster list and token. - Edit
etcd.yamlon each node so the data volume points at the restored directory. - Move the manifests back. The kubelet starts etcd, then the API server.
- Check member health and list the members.
Restoring each member
This example restores the first of three members. The names and IP addresses are placeholders. Replace them with your own.
etcdutl snapshot restore /var/backups/etcd-snapshot.db \
--name cp1 \
--data-dir /var/lib/etcd-restored \
--initial-cluster cp1=https://10.0.0.11:2380,cp2=https://10.0.0.12:2380,cp3=https://10.0.0.13:2380 \
--initial-cluster-token etcd-restored-1 \
--initial-advertise-peer-urls https://10.0.0.11:2380On cp2 and cp3, change only --name and --initial-advertise-peer-urls. The --initial-cluster list and the token must be identical on all three nodes. A new token keeps the restored members from joining any old cluster that is still running.
Then update the data volume in each node's manifest, as in the single-node restore:
# /etc/kubernetes/manifests/etcd.yaml (excerpt)
volumes:
- hostPath:
path: /var/lib/etcd-restored
type: DirectoryOrCreate
name: etcd-dataChecking the result
Once all three members are running, confirm that they agree:
ETCDCTL_API=3 etcdctl \
--endpoints=https://10.0.0.11:2379,https://10.0.0.12:2379,https://10.0.0.13:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
endpoint health --write-out=tableThen run kubectl get nodes and kubectl get pods -A. The objects should match the time of the snapshot.
Common errors
- Restoring only some members. The remaining members keep old data and conflict with the restored ones. Restore all of them.
- Different snapshot files. Copy one file and compare checksums with
sha256sumbefore you restore. - Mismatched
--initial-clusterlists. Members cannot find each other. Compare the lists on every node. - API servers still running. They write to a half-restored store. Stop them first.
Exercise
You restored two of your three etcd members from a snapshot, but the third node was unreachable, so you skipped it. What should you do, and why?
Show answer
Restore the third member from the same snapshot, using its own name and peer URL and the same --initial-cluster list and token, before starting the cluster. If it keeps its old data, its history conflicts with the restored members, so it cannot rejoin cleanly.