BM: Baca dalam Bahasa Melayu
World K9: Cluster Admin
etcd backup and restore
You will learn: to photocopy the order book with etcdctl, and bring a lost object back with etcdutl.
Checked with Kubernetes 1.37 on 1 Nov 2026
The problem
At 2 a.m. someone deleted the shop’s Deployment. Its YAML was never saved in Git. What could still bring it back?
Pick one answer.
Watch
kind-dev namespace defaultAn etcd snapshot: A photocopy of the order book (etcd) at one moment. Keep it off the cluster, somewhere safe. is a photocopy of the order book. etcdctl asks the running etcd for it. Keep the copy off the cluster.
Try it
Build the save command. Each piece shows what it means.
Tap the pieces in the right order.
Hint
Tool, where, the three certificate flags, then snapshot save and the file.Watch
kind-dev namespace defaultTrap: without certificate flags, etcdctl prints one line, then waits forever. Press Ctrl+C. Then add --cacert, --cert and --key.
Try it
Your turn. Open the office node, save a snapshot, then check it.
kind-dev namespace defaultdev-control-planeOpenManagerNo trays here.
dev-workerOpen- shop·9448k
- shop·q725x
dev-worker2Open- shop·ddlcm
etcdctl --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.key snapshot save /opt/backup.db
etcdutl --write-out=table snapshot status /opt/backup.dbPredict
On etcd 3.7, you type etcdctl snapshot status /opt/backup.db. What happens?
Pick one answer.
Try it
The shop was deleted after the snapshot. etcdutl: The tool for etcd's files: it checks and restores a snapshot. etcdctl talks to a running etcd. restores the copy into a new, empty folder. Then point etcd there. Danger: newer objects are lost.
kind-dev namespace defaultdev-control-planeOpenManagerNo trays here.
dev-workerOpenNo trays here.
dev-worker2OpenNo trays here.
etcdutl --data-dir /var/lib/etcd-restore snapshot restore /opt/backup.db
sed -i 's#/var/lib/etcd$#/var/lib/etcd-restore#' /etc/kubernetes/manifests/etcd.yamlCheck
Put a restore in order.
First step at the top. Put these in order. Use the arrows, or drag.
- Wait: etcd restarts, then the API answers
- etcdutl --data-dir <new folder> snapshot restore
- Point etcd.yaml at the new folder
- kubectl get deployments
- etcdutl snapshot status: is the copy healthy?
You did it!
You can now back up etcd and restore a lost object.
Go deeper (optional)
kind nodes have no etcdctl. There, run it inside the etcd pod. Only /var/lib/etcd and the certificates are shared with the node.
kind-dev namespace defaultReal mission
kubectl -n kube-system exec etcd-<cluster>-control-plane -- etcdctl --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.key snapshot save /var/lib/etcd/backup.dbdocker cp <cluster>-control-plane:/var/lib/etcd/backup.db ./backup.db
0 of 2 steps done · Your ticks are saved.
Bahasa Melayu
Pukul 2 pagi, seseorang padam Deployment shop. YAML-nya tak pernah disimpan dalam Git. Apa yang masih boleh pulihkannya?
etcd snapshot ialah fotokopi buku pesanan. etcdctl minta salinan itu daripada etcd yang sedang berjalan. Simpan salinan itu di luar kluster.
Bina arahan simpan. Setiap kepingan tunjuk maksudnya.
Perangkap sebenar: tanpa flag sijil, etcdctl cetak satu baris dan tunggu selamanya. Tekan Ctrl+C. Kemudian tambah --cacert, --cert dan --key.
Giliran anda. Buka node pejabat, simpan snapshot, kemudian semak.
etcdctl --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.key snapshot save /opt/backup.db
etcdutl --write-out=table snapshot status /opt/backup.db
Pada etcd 3.7, anda taip etcdctl snapshot status /opt/backup.db. Apa berlaku?
Shop dipadam selepas snapshot diambil. etcdutl pulihkan salinan ke folder baharu yang kosong. Kemudian tunjukkan etcd ke situ. Bahaya: objek yang lebih baharu hilang.
etcdutl --data-dir /var/lib/etcd-restore snapshot restore /opt/backup.db
sed -i 's#/var/lib/etcd$#/var/lib/etcd-restore#' /etc/kubernetes/manifests/etcd.yaml
Susun langkah pemulihan ikut urutan.
Kini anda boleh sandarkan etcd dan pulihkan objek yang hilang.
You finished this before. Practice is always welcome!
Official docs: Kubernetes: operating etcd clusters (backup and restore) · etcd 3.7: disaster recovery
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?