etcd Backup and Restore for Kubernetes Disaster Recovery
etcd backup and restore is the recovery path when a Kubernetes control plane loses its datastore. This lesson covers taking consistent snapshots with etcdctl, verifying and storing them off-cluster, restoring with etcdutl into a new data directory, handling quorum loss, and rehearsing the whole runbook before an incident demands it.
## Introduction
etcd backup and restore is the discipline that decides whether a lost Kubernetes control plane is an incident or a rebuild-from-scratch project. etcd holds every object the API server serves, so this lesson covers verified snapshots, off-cluster storage, restore into a new data directory, and rehearsals that prove recovery works before you need it.
Illustrative composite: a storage fault corrupts etcd on two of three control-plane nodes during a weekend change. The team finds snapshots on the first node, dated eleven months earlier, taken by an engineer who has since left. The cluster comes back, but a year of namespaces, RBAC, and custom resources must be reconstructed from Git and memory. The backup job existed. Nobody had verified it, copied it off the node, or rehearsed a restore.
This lesson follows kubeadm cluster administration, where snapshots appeared as an upgrade precheck. Here they get the full treatment, because etcd is the cluster's memory. The Kubernetes architecture lesson explains where etcd sits in the control plane; this lesson explains how to bring that memory back when the machines holding it are gone.
The 5-minute takeaway
Take snapshots on a schedule with etcdctl snapshot save, verify each one, encrypt and copy it off the cluster, and rehearse restoring into a new data directory at least quarterly. A snapshot you have never restored is a hope, not a backup. Restore creates a new cluster identity, so treat it as a rebuild, not a rollback.
1. etcd backup and restore: what etcd holds and what it does not
etcd backup and restore protects the Kubernetes datastore: every Deployment, Secret, RBAC rule, custom resource, and lease lives in etcd under the registry prefix. A snapshot captures that state at one revision. It does not capture container images, volume data, or node configuration, which need their own backup paths.
Understanding the boundary prevents false confidence. Restoring etcd brings back the objects that describe workloads, including PersistentVolumeClaims, but the data inside volumes lives on storage systems that etcd never sees. A restored cluster can therefore reference volumes that no longer exist. Disaster recovery needs both layers: etcd snapshots for cluster state, and storage-level backup or replication for volume data, plus Git for the manifests you would reapply anyway.
etcd is a Raft-based key-value store. Members elect a leader, replicate writes, and require a majority quorum to accept changes. A three-member cluster tolerates one member loss; a five-member cluster tolerates two. Quorum is why etcd backup and restore decisions differ by failure type: losing one member is a member replacement, losing quorum is a restore. Knowing which situation you are in is the first diagnostic step, before any command runs.
| Item | In an etcd snapshot? | Backup responsibility |
|---|---|---|
| Deployments, Services, RBAC, CRDs and custom resources | Yes | etcd snapshot |
| Secrets | Yes, as stored | etcd snapshot, encrypted at rest in storage |
| Volume contents | No | Storage snapshots, replication, application backup |
| Container images | No | Registry retention and rebuild pipeline |
| Node OS and kubelet config | No | Image builds, configuration management, kubeadm config in Git |
One consequence deserves emphasis: a snapshot contains every Secret in the cluster, in whatever form etcd stored them. If encryption at rest is not configured, Secret values are base64-encoded, not encrypted, inside the snapshot file. Handle snapshots with the same care as the cluster's most sensitive credential, because that is what they are.
2. etcd backup and restore: find endpoints and certificates
etcd backup and restore commands need three things: the etcd client endpoint, the CA certificate, and a client certificate and key. On kubeadm clusters these live in the etcd static Pod manifest and under the PKI directory. Read them from the manifest instead of copying paths from memory or old runbooks.
On a control-plane node, inspect /etc/kubernetes/manifests/etcd.yaml for the listen-client-urls, cert-file, key-file, and trusted-ca-file arguments, plus the image tag that tells you the etcd version. The version matters because tooling changed across releases: etcdctl snapshot commands are the classic path, while newer etcd versions move restore and status functions into etcdutl. Match the tool to the version your cluster actually runs.
Certificates for etcd client access sit under /etc/kubernetes/pki/etcd/ on kubeadm clusters: ca.crt, server.crt, and server.key are the usual trio for local snapshot commands. Permissions are tight by design, so snapshot jobs run as root on the control-plane node or inside a privileged context. That privilege is another reason snapshots belong in a controlled job with an audit trail, not in an ad-hoc shell someone remembers during incidents.
External etcd topologies change the details, not the method. Endpoints point at dedicated etcd hosts, certificates come from wherever that deployment stores them, and the snapshot command is otherwise identical. Record the endpoint and certificate paths for your topology in the runbook, and verify them during every rehearsal, because certificate rotation and node replacement quietly move these files.
3. etcd backup and restore: take a consistent snapshot
etcd backup and restore begins with etcdctl snapshot save, which streams a consistent copy of the keyspace at a single revision from a running member. The API server keeps serving during the snapshot. Set the API version to 3, pass the endpoint and certificates, and write the file to a path with a timestamped name.
A snapshot is internally consistent even while writes continue, because etcd serves it from a read transaction at one revision. You never stop etcd or the API server to take one. That makes frequent snapshots cheap: the cost is roughly the size of the database written to disk, plus the copy off the node. For most clusters the database is hundreds of megabytes to a few gigabytes, small enough that hourly snapshots are reasonable where recovery point objectives demand them.
Name snapshots so the newest is obvious and retention is mechanical: cluster name plus UTC timestamp. Avoid overwriting a fixed filename, because a failed snapshot job that truncates the only copy converts a backup system into a data-loss system. Write to a new file, verify it, and only then let retention delete older files.
4. etcd backup and restore: verify every snapshot
etcd backup and restore treats verification as part of the backup, not a follow-up task. Run the snapshot status command to confirm the file parses, the hash matches, and the key count and revision look sane. A snapshot job that exits zero but produces a truncated file is worse than no job, because it creates false confidence.
Status output gives you hash, revision, total keys, and size. A healthy snapshot of a real cluster has a nonzero key count in the thousands or more and a size close to the live database. A near-empty snapshot after a busy month is a red flag: perhaps the job pointed at the wrong endpoint, or at a fresh member that never joined. Compare snapshot size against the etcd database size metric so silent shrinkage gets noticed.
Verification also means checking the job, not just the file. Alert when no successful snapshot lands within the expected interval, because the most common backup failure is a job that stopped running months ago: a CronJob deleted in a cleanup, a timer on a node that was replaced, credentials rotated without updating the job. The alert should fire on absence of success, not only on reported failure.
Keep a simple manifest beside the snapshots: cluster name, etcd version, snapshot revision, timestamp, and the Kubernetes version at capture time. During a restore, that metadata decides which tool version and which control-plane version to rebuild with. Guessing versions under pressure wastes the first hour of recovery.
5. etcd backup and restore: store snapshots off-cluster, encrypted
etcd backup and restore only works if snapshots survive the failure they protect against, so copy every verified snapshot off the control-plane nodes into object storage or a backup system in a different failure domain. Encrypt snapshots in transit and at rest, restrict who can read them, and set retention to match your recovery objectives.
A snapshot stored only on the node it backs up protects against exactly one scenario: accidental deletion while the node survives. Disk failure, node loss, ransomware, and a bad cleanup script all take the snapshot with the cluster. Copy to object storage with versioning and, where the stakes justify it, immutability or object lock, so a compromised cluster credential cannot delete the backups it might need.
Encryption is not optional decoration. The snapshot contains every Secret, so encrypt it with a key managed outside the cluster, such as a cloud KMS key or an offline key held by the platform team. Access to restore should require the same approval as cluster-admin access, because anyone holding a snapshot and a restore path effectively holds the cluster. Audit reads of the backup bucket the way you audit production credential use.
| Storage choice | Protects against | Weakness |
|---|---|---|
| Same node disk | Accidental object deletion | Node loss takes backup with it |
| Object storage, same account | Node and cluster loss | Account compromise can delete backups |
| Object storage with versioning and lock | Deletion and ransomware | Restore needs lock-aware process |
| Separate account or offline copy | Account-level compromise | Slower retrieval during incidents |
Retention should cover the mistakes you might discover late. Keeping only the last day of snapshots fails when corruption is noticed a week later and every retained snapshot contains it. A common pattern is hourly snapshots for a day, daily for two weeks, and weekly for a quarter, adjusted to the cluster's change rate and compliance needs.
6. etcd backup and restore: automate with a job you can audit
etcd backup and restore belongs in automation: a systemd timer on control-plane nodes or a CronJob with the right access, running the save, verify, and copy steps as one auditable unit. Manual snapshots happen before upgrades; scheduled snapshots are what save you from failures nobody scheduled.
A systemd timer on each control-plane node is the simplest reliable pattern for kubeadm clusters. It runs as root, reads the local certificates, writes to a local directory, verifies, and copies to object storage. Running it on every control-plane node gives redundancy, with retention handled centrally so copies do not multiply forever. The job should be idempotent and should fail loudly: nonzero exit, log line, and an alert path.
Pin the etcd image version to match the cluster, and update it during cluster upgrades. A snapshot tool far from the server version is an avoidable risk. The CronJob form also needs the copy-off-cluster step, usually a second container or a follow-up job with object-storage credentials scoped to write-only access on the backup prefix.
7. etcd backup and restore: restore creates a new cluster identity
etcd backup and restore works differently than most engineers expect: restore does not load data into a running member. It builds a brand-new data directory with fresh member and cluster identity from the snapshot, and you then start etcd against that directory. Restoring is a rebuild, so plan downtime and rejoin steps accordingly.
The fresh identity is deliberate. A restored member must not confuse itself with the old cluster's membership, so the restore command takes the member name, initial cluster membership, peer URLs, and a new cluster token. Every member of a multi-node restore uses the same snapshot with its own name and peer URL, producing a new etcd cluster whose contents match the snapshot revision. The API server then reads a datastore that looks like the old cluster at that moment in time.
Because restore is offline, the sequence starts by stopping etcd and the API server. On kubeadm clusters that means moving the static Pod manifests out of /etc/kubernetes/manifests so the kubelet stops those Pods. Restore into a new directory such as /var/lib/etcd-restored, never over the live data directory. Keeping the old directory intact preserves the option to investigate or fall back, and costs only disk space.
Expect the restored cluster to be a point-in-time view. Objects created after the snapshot are gone, and controllers will reconcile toward the restored state, which can mean recreating resources that were deleted after the snapshot or removing ones created later. Tell stakeholders the recovery point before you restore, and plan a reconciliation review afterward, especially for resources managed by operators and GitOps controllers.
8. etcd backup and restore: single control-plane restore runbook
etcd backup and restore for a single control-plane cluster follows a tight sequence: stop the API server and etcd static Pods, restore the snapshot into a new data directory, point etcd at it, restart the control plane, and verify objects before letting workloads reconnect. Practise this sequence until it is boring.
Start by confirming the situation really calls for restore. A single-node control plane with a corrupt data directory and a verified snapshot is the clear case. Preserve evidence first: copy the old data directory and relevant logs aside, because post-incident questions will ask what failed. Then stop the static Pods by moving kube-apiserver.yaml and etcd.yaml out of the manifests directory, and confirm the processes are gone before touching data.
Verify in widening circles: etcd health, API server readiness, kubectl get nodes, system Pods, then application namespaces. The kubectl master guide covers the verification commands for each circle. Expect some Pods to restart as controllers reconcile restored state against running workloads. Watch for resources that reappear from the snapshot but should not exist, and for Secrets or tokens rotated after the snapshot that clients no longer accept. The restore ends when workloads are verified, not when the API answers.
9. etcd backup and restore: multi-member and quorum-loss recovery
etcd backup and restore for a multi-member cluster restores the same snapshot on every member with that member's identity, forming a new cluster with matching contents. When only one member is lost and quorum survives, skip restore entirely: remove the dead member and add a replacement, which is faster and safer.
The decision hinges on quorum. With three members and one dead, etcd still serves reads and writes, so the correct recovery is member replacement: remove the failed member with etcdctl member remove, add the new member, and start it with the updated initial cluster configuration. Restoring from snapshot in that situation would throw away every write since the snapshot for no benefit.
With quorum lost, restore is the path. Stop etcd and the API server on all control-plane nodes. On each node, restore the same snapshot file with that node's name and peer URL and a shared new cluster token. Swap data directories, restart etcd everywhere, confirm a leader elects and members report healthy, then restart the API servers. The same-snapshot rule is absolute: members restored from different snapshots form a cluster with divergent histories, which etcd will not reconcile for you.
After a quorum-loss restore, expect the point-in-time effects at cluster scale. Leases, leader elections, and controller state revert to the snapshot moment. Operators reconcile, GitOps controllers compare Git against restored state and may reapply changes made after the snapshot, which is usually what you want. Announce the recovery point clearly so application teams can check their own data paths, especially anything written outside Kubernetes after the snapshot time.
10. etcd backup and restore: what restore does not fix
etcd backup and restore recovers cluster state, but it does not repair the cause of the loss, restore volume data, or fix broken certificates and node configuration. Treat restore as one layer of disaster recovery, and pair it with storage backup, Git-held manifests, and the node recovery skills from the previous lesson.
If etcd corrupted because a disk is failing, restoring onto the same disk invites a repeat. Replace suspect hardware or move to healthy nodes first. If the loss came from an accidental deletion of objects, restore may be heavier than needed; reapplying manifests from Git or restoring specific objects from a snapshot inspection can recover with less disruption. The GitOps best practices guide covers keeping those manifests in Git so reapplying them is routine. Match the recovery tool to the failure: member replacement for one dead member, targeted reapply for deleted objects, full restore for quorum loss or corruption.
Volume data needs its own plan. The storage lessons on PVC provisioning and StatefulSet patterns cover how claims bind to volumes; disaster recovery for the data inside those volumes belongs to storage snapshots and application-level backup. A restored etcd that references volumes destroyed with the old cluster gives you a control plane describing a world that no longer exists, so recovery verification must include data checks for stateful workloads.
Certificates and PKI deserve a place in the recovery kit. A snapshot restored onto fresh nodes still needs the cluster CA and serving certificates so clients trust the API server. Back up /etc/kubernetes/pki with the same off-cluster discipline as snapshots, encrypted and access-controlled. The kubeadm administration lesson covers certificate renewal; recovery planning should assume you may need to rebuild trust material, not just data.
| Symptom | First check | Fix |
|---|---|---|
| Snapshot save fails with connection refused | etcd endpoint and member health from the manifest | Start or repair the etcd member; snapshot from a healthy member |
| Snapshot status shows zero or tiny key count | Endpoint used by the job and live database size | Point the job at the real member; compare size against the etcd database metric |
| Restore completes but API server will not start | etcd health, PKI files, and manifest data-dir path | Restore the PKI backup, point etcd at the restored directory, restart static Pods |
| Restored members do not elect a leader | Same snapshot file, per-member name and peer URLs, shared new token | Re-restore every member from the identical snapshot with matching identity values |
| Objects reappear that were deleted after the snapshot | Recovery point versus post-snapshot changes | Reconcile with Git and application owners; reapply deletions deliberately |
11. etcd backup and restore: rehearsals and recovery objectives
etcd backup and restore is only proven by rehearsal: restore the latest snapshot into an isolated environment, start a control plane against it, and verify that key objects and workloads appear. Schedule rehearsals quarterly, measure how long recovery takes, and record the recovery point and time objectives the rehearsal actually achieved.
A rehearsal environment can be modest: one virtual machine with the control-plane binaries, the PKI backup, and the snapshot. Restore, start etcd and the API server, and run the verification queries: namespaces, critical Deployments, RBAC bindings, custom resources. The goal is to discover the missing certificate, the wrong etcd version, or the snapshot that only exists on a decommissioned node while the stakes are low.
Measure two numbers. Recovery point objective is how much state you lose: the age of the newest verified snapshot at failure time. Recovery time objective is how long until the API serves and workloads verify. Snapshot frequency sets the first; rehearsal quality sets the second. Teams often discover their real RTO is dominated by small delays: finding credentials, locating the right snapshot, waiting for approvals. Rehearsals surface those delays so runbooks can remove them.
Write rehearsal findings into the runbook immediately. Every surprise, from a moved certificate path to a tool version mismatch, becomes a line in the procedure and a check in the snapshot job. A runbook that has survived three rehearsals is an operational asset. A runbook written once and never executed is a hypothesis. Rotate rehearsal duty among the team so recovery knowledge survives holidays, resignations, and the simple fact that the person who wrote the procedure is rarely the person awake when it is needed.
12. etcd backup and restore: disaster recovery checklist
etcd backup and restore is production-ready when snapshots are scheduled, verified, encrypted, stored off-cluster, and restored in rehearsal on a regular cadence. Use the checklist below to audit your current setup, and treat any unchecked item as a recovery gap with a named owner and a date.
Audit honestly. Most clusters have a snapshot job; far fewer have verified restores, off-cluster copies with deletion protection, and a rehearsed quorum-loss procedure. The gap between those two states is exactly where long outages live. Work the checklist from the top, because later items depend on earlier ones: there is no point rehearsing a restore from snapshots that were never copied off the node. The Kubernetes best practices guide covers the wider production habits this recovery discipline sits inside.
- [ ] Snapshot job scheduled on control-plane nodes; absence of success alerts
- [ ] Every snapshot verified with status output; size and key count sanity-checked
- [ ] Snapshots copied off-cluster, encrypted, versioned, and access-audited
- [ ] PKI backup and kubeadm configuration stored with the snapshots
- [ ] Retention covers late-discovered corruption, not just the last day
- [ ] Single-node restore rehearsed into a new data directory
- [ ] Quorum-loss procedure documented: same snapshot, per-member identity, new token
- [ ] Recovery point and time measured in rehearsal and recorded
The final lesson of this series returns to everyday triage: Kubernetes Pod stuck Pending works through scheduler, taint, PVC, and quota causes with the same evidence-first method. Disaster recovery keeps the cluster alive; Pending triage keeps workloads moving on the cluster you recovered.
Frequently Asked Questions
How often should etcd backup and restore snapshots run?
Match frequency to your recovery point objective. Hourly snapshots suit clusters where losing an hour of state is acceptable; busy clusters may snapshot more often, and small clusters can run daily. The cost is roughly the database size per snapshot, so frequency is usually limited by retention and copy bandwidth rather than by etcd load.
What is the difference between etcdctl and etcdutl in etcd backup and restore?
etcdctl talks to a running etcd member and takes snapshots with snapshot save. etcdutl works offline on snapshot files and data directories, handling status checks and restore in newer etcd versions. Use the tool version matching your cluster, and confirm from the etcd image tag which version you run before writing the runbook.
Why does etcd backup and restore create a new data directory?
Restore builds a fresh member and cluster identity from the snapshot so the restored etcd cannot confuse itself with the old cluster's membership. Writing into a new directory also preserves the old data for forensics or fallback. You then point etcd at the new directory and start it; restore never edits a live member in place.
When should etcd backup and restore be skipped in favour of member replacement?
When one member is lost but quorum survives, replace the member instead of restoring. Remove the dead member, add a replacement, and let Raft replicate current state to it. Restoring from snapshot in that case discards every write since the snapshot. Reserve full restore for quorum loss, corruption, or total control-plane loss.
Are etcd backup and restore snapshots safe to store in object storage?
Yes, with controls. Encrypt snapshots, restrict read access to the platform team, enable versioning or object lock, and audit access. A snapshot contains every Secret in the cluster, so treat the backup bucket like a credential store. Copying snapshots off-cluster is essential; storing them unprotected is not.
What else must etcd backup and restore planning include besides snapshots?
Volume data backup, the cluster PKI, kubeadm configuration, and Git-held manifests. A restored etcd references volumes and certificates that must also exist. Pair snapshots with storage-level backup for stateful data, keep PKI backups encrypted off-cluster, and verify data paths for critical workloads during recovery, not just API availability.
How do you prove etcd backup and restore actually works?
Rehearse it. Restore the newest snapshot into an isolated environment, start etcd and the API server, and verify namespaces, RBAC, and key workloads. Measure recovery time and the age of the snapshot you used. Repeat quarterly and after major upgrades, and fold every surprise back into the runbook and snapshot job checks.
Preparing for Senior Platform & SRE Interviews
Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.
Explore Interview Scenarios →