What it does
etcd is a distributed key-value store (Raft consensus) on port 2379 (clients) and 2380 (peers). Kubernetes keeps every object (pods, secrets, config) in it. If etcd is lost without a backup, the cluster is lost. etcdctl (API v3) reads keys, checks health and makes snapshots; etcdutl restores snapshots and checks them offline.
On kubeadm clusters etcd runs as a static pod and needs the client certificates in /etc/kubernetes/pki/etcd/.
How to write it
ETCDCTL_API=3 etcdctl --endpoints=URL --cacert=CA --cert=CRT --key=KEY COMMAND
etcdutl snapshot restore FILE --data-dir DIRMain parts
Commands
endpointhealth/endpointstatus- Is etcd healthy? Who is leader?
memberlist- Cluster members.
snapshotsaveFILE- Make a backup.
snapshotstatusFILE(etcdutl)- Check a backup.
snapshotrestoreFILE(etcdutl)- Restore into a new data folder.
getKEY[--prefix --keys-only]- Read keys.
putKEYVALUE/delKEY- Write / delete (never on a Kubernetes etcd by hand).
defrag- Free space after compaction.
alarmlist/alarmdisarm- Space alarms.
Options 5
Most used
Flags
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Set the TLS flags once (kubeadm)
2Health and members
etcdctl endpoint health etcdctl endpoint status -w table etcdctl member list -w table3Back up (CKA)
etcdctl snapshot save /opt/backup/etcd-$(date +%F).db etcdutl snapshot status /opt/backup/etcd-2026-10-27.db -w table4Find the cert paths from the static pod
grep -E "cert-file|key-file|trusted-ca-file|listen-client-urls" /etc/kubernetes/manifests/etcd.yaml5Restore (CKA)
6See how Kubernetes stores objects
etcdctl get /registry/namespaces --prefix --keys-only | head7Check that Secrets are encrypted at rest
etcdctl get /registry/secrets/shop/db | hexdump -C | head -3You should see
k8s:enc:aescbc:v1:ork8s:enc:kms, not clear text.8Fix a full database (NOSPACE alarm)
etcdctl alarm list etcdctl defrag etcdctl alarm disarm9Back up every night with a timer
cat /usr/local/bin/etcd-backup.sh #!/bin/bash etcdctl snapshot save /opt/backup/etcd-$(date +%F).db && find /opt/backup -name 'etcd-*.db' -mtime +7 -delete10k3s with embedded etcd
k3s etcd-snapshot save --name manual
Nothing matches this filter.
Watch out
- An etcd snapshot contains all Secrets — encrypt it and store it off the node.
- Never write keys by hand in a Kubernetes etcd.
- Restore on all control-plane nodes the same way, or the cluster splits.
Files
/var/lib/etcd/- Data folder (kubeadm).
/etc/kubernetes/manifests/etcd.yaml- Static pod (kubeadm).
/etc/kubernetes/pki/etcd/- Certificates.
Tips to remember
- CKA: read the paths from etcd.yaml, do not guess them;
etcdctl snapshot savemust use the right certs.
Exit codes
0 | Success. |
1 | Error. |