Snapshots compaction and recovery
History, compaction and defragmentation
etcd retains historical key versions so clients can request prior states or watch changes. Compaction discards superseded history through a chosen revision; it does not delete the current value of a key. Clients that need compacted history must recover with a fresh current-state read. Defragmentation is a different maintenance operation: it can return unused backend file space to the filesystem. Live defragmentation can block operations on the target member; schedule it with an approved runbook rather than running it across all members at once.
History: 40 → 41 → 42 → 43Compaction through 42: older history unavailable; current state at 43 remains.Backend file size need not shrink immediately.Space pressure is an operational signal
Distinguish logical data in use from the allocated backend file size and the configured storage quota. A quota alarm can limit write operations; do not assume a restart, arbitrary key deletion or a larger quota solves the cause. Investigate workload churn, retention, disk headroom and member health. Review version-specific maintenance procedures, verify a usable backup, and recheck health after each approved maintenance action.
Synthetic observations (MiB): file=900, in-use=320, quota=1000Unused space inside file is not the same as free space on the filesystem.Snapshot evidence and coverage
A snapshot captures etcd database state, not the files in a PersistentVolume, external database, node filesystem or external identity system. Use version-compatible snapshot tooling in a separately authorized environment. The etcd v3.6 documentation uses etcdutl snapshot status to inspect a snapshot offline. Metadata and a hash can help identify a backup but cannot establish successful restoration. Protect the file, restrict access and store recovery keys separately.
Synthetic metadata (not actual tool output):revision: 1200key_count: 84file_hash_verified: truerestore_rehearsed: falseRestore to an isolated cluster
Restoration from a snapshot creates new logical etcd membership. Plan compatible tooling and data directories, peer identities, certificates, trusted CA material, network isolation and API server configuration. Restore only in a separately approved disposable environment and keep it disconnected from production controllers and external systems. Check that encryption providers and the historical keys required to decrypt stored API objects are recoverable. A snapshot alone does not include those external dependencies.
Offline restore gates:compatible tooling → isolated destination → protected snapshot → recovery keys → healthy API → workload/data checksRevisions after a restore
Restoring an older snapshot can make revision numbers appear to move backwards relative to clients that observed later writes. etcd v3.6 provides revision bump and mark-compacted restore options: the bump must cover the possible revision advance and the compaction marker forces stale watches to recover rather than wait on invalid history. This does not restore lost writes. Size the bump from a conservative bound on elapsed time and transaction rate plus margin, using the exact supported tooling and verified recovery guidance. Do not calculate from API resourceVersion values.
Synthetic bound: snapshot=1200, max observed etcd revision=1700bump=700 → restored revision=1900 (>1700)mark compacted: planned; stale clients must relistChanges after snapshot are still absent.Verification before returning service
A rehearsal should confirm member health and majority, API readiness, expected synthetic objects, successful decryption, controller cache refresh and reconciliation. Independently restore and verify application data, then test workload behavior before allowing traffic. Compare the recovered state with the recovery objective. Stop if identity, key material, version compatibility or expected data cannot be verified. Never overwrite original data directories as a learning shortcut.
Snapshot status: validAPI health: passApplication record check: missingDecision: recovery incomplete; keep traffic closed.Practice and next step
Use recovery-cases.json and maintenance-cases.json. Calculate a safe illustrative revision bump, distinguish history cleanup from file-space reclamation, and classify the recovery gates. Run the provided Python tests only after predicting the results. The next chapter expands this into application backups, recovery objectives and disaster rehearsals.
Further reading
Primary documentation (etcd v3.6 where versioned; checked 2026-11-28):
- https://etcd.io/docs/v3.6/dev-guide/interacting_v3/
- https://etcd.io/docs/v3.6/op-guide/maintenance/
- https://etcd.io/docs/v3.6/op-guide/recovery/
- https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/
- https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/
- https://kubernetes.io/docs/concepts/security/api-server-bypass-risks/
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Snapshots compaction and recovery — knowledge check
Distinguish compaction from defragmentation, evaluate snapshot evidence, and plan an isolated revision-aware recovery.
What is the purpose of MVCC compaction?
Which operation can return unused backend file space to the filesystem?
What is missing from an etcd snapshot of Kubernetes API state?
Snapshot revision is 1200 and highest possible old revision is 1700. Which example bump produces a strictly higher revision?
A snapshot hash passes but required encryption keys are unavailable. What is the correct recovery decision?