CKA — etcd Snapshot Restore
Restoring from an etcd Backup
Restoring etcd is more complex than backing up. You restore to a new data directory and then update the etcd configuration to use it.
Step 1 — Restore the Snapshot
ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd-backup.db \
--data-dir=/var/lib/etcd-restored
This creates a new data directory at /var/lib/etcd-restored with the restored data.
Important: Do NOT restore directly to /var/lib/etcd. Always restore to a new directory first.
Step 2 — Update the etcd Static Pod Manifest
Edit the etcd manifest to point to the new data directory:
sudo vi /etc/kubernetes/manifests/etcd.yaml
Make three changes:
1. Update the –data-dir flag:
# Before
- --data-dir=/var/lib/etcd
# After
- --data-dir=/var/lib/etcd-restored
2. Update the volumeMount mountPath:
volumeMounts:
- mountPath: /var/lib/etcd-restored # <-- Update this
name: etcd-data
3. Update the hostPath:
volumes:
- hostPath:
path: /var/lib/etcd-restored # <-- Update this
type: DirectoryOrCreate
name: etcd-data
Step 3 — Wait for etcd to Restart
The kubelet detects the manifest change and automatically restarts the etcd Pod. Wait 30-60 seconds:
# If kubectl works
kubectl get pods -n kube-system | grep etcd
# If kubectl is not responding, use crictl
sudo crictl ps | grep etcd
Step 4 — Verify the Restoration
kubectl get nodes
kubectl get pods --all-namespaces
kubectl get deployments --all-namespaces
Complete Restore Workflow
| Step | Command | Purpose |
|---|---|---|
| 1 | etcdctl snapshot restore –data-dir=new-dir | Restore to new directory |
| 2 | Edit etcd.yaml –data-dir | Point etcd to new directory |
| 3 | Edit etcd.yaml volumeMount | Update mount path |
| 4 | Edit etcd.yaml hostPath | Update host path |
| 5 | Wait 30-60 seconds | kubelet restarts the Pod |
| 6 | kubectl get nodes | Verify cluster is functional |
Common Restore Mistakes
| Mistake | Consequence | Prevention |
|---|---|---|
| Restoring to /var/lib/etcd directly | May corrupt existing data | Always use a new directory |
| Forgetting to update volume mounts | etcd Pod cannot access data | Update all three locations |
| Not waiting for restart | kubectl commands fail temporarily | Wait 30-60 seconds |
| Wrong file permissions | etcd cannot read data | Ensure root ownership |
Exam tip: This is a high-value exam question. Practice the full workflow until you can do it without looking at notes. Remember the three edits in etcd.yaml.
Next: Verify Backup ->