Sub topic 10
Taking an etcd snapshot before you start
This chapter assumes you can run kubectl and have shell access to a kubeadm control plane node. It also assumes you know that the control plane stores cluster state in etcd.
Why the snapshot matters
Kubernetes does not support downgrading a cluster. If an upgrade damages the control plane or the stored objects, you can't simply install the old version again. The main recovery path is to restore etcd from a snapshot taken before you began.
etcd is the key-value store that holds every API object: Deployments, Secrets, ConfigMaps, and so on. A snapshot is a point-in-time copy of that data in a single file.
Taking the snapshot
Run this on a control plane node. The paths are the kubeadm defaults. The etcdctl tool must be installed on the node or run from the etcd container.
ETCDCTL_API=3 etcdctl snapshot save /var/backups/etcd-pre-upgrade.db \
--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.keyThe three certificate flags are needed because etcd only accepts clients that present a certificate signed by its own CA. If the command fails with a TLS error, check these paths first.
Checking the snapshot
A file on disk is not proof of a usable backup. Check it before you rely on it:
ETCDCTL_API=3 etcdutl snapshot status /var/backups/etcd-pre-upgrade.db --write-out=tableThe table shows the hash, revision, total key count, and size. A key count of zero or a very small file means something went wrong. Older etcd releases offer the same check as etcdctl snapshot status.
What to back up besides etcd
etcd holds the API objects, but it does not hold everything you need to rebuild a control plane node. Copy these as well:
/etc/kubernetes/, which contains the manifests, certificates, and kubeconfig files.- Any custom kubeadm configuration file you used.
- Any add-on settings that live outside the cluster.
Where to keep it
Copy the snapshot off the node immediately. A backup that sits only on the machine you are about to change does not help if that machine is lost.
Common errors
| Symptom | Likely cause |
|---|---|
| `context deadline exceeded` | Wrong endpoint, or etcd is not reachable from where you run the command |
| `certificate signed by unknown authority` | Wrong `--cacert` path |
| `permission denied` | The command was run without `sudo` and cannot read the key files |
| Snapshot is tiny | The command hit a different, empty etcd instance |
On a multi-node control plane, a snapshot from one member is enough, because members replicate the same data. Take it from a healthy member.
Exercise
You saved a snapshot and the file exists, but you did not run a status check. Why is that not enough, and what would you do next?
Show answer
A file existing does not show it holds valid data. The save could have been truncated, or it could have come from the wrong etcd instance. Run etcdutl snapshot status on the file and confirm a plausible key count and size. Then copy the file off the node before starting the upgrade.