Backup candidates
Resource Configuration
All Kubernetes object definitions (pods, deployments, services, etc.)
ETCD Cluster
The cluster’s state and configuration database
Persistent Volumes
Application data stored in persistent volumes
Resource configuration backup
Query thekube-apiserver using kubectl to export all objects as YAML and store them as a backup copy.
ETCD backup
ETCD is the database of the Kubernetes cluster, storing all cluster state — nodes, pods, secrets, and more. When configuring ETCD, a data directory is specified where all ETCD data is stored. You can back up this directory directly.etcd.service
Creating an ETCD snapshot
Set
ETCDCTL_API=3 before running any etcdctl backup or restore commands.- You can specify any path to save the snapshot.
- Always provide the
--cacert,--cert,--key, and--endpointsflags when saving a snapshot.
ETCD restore
Stop the kube-apiserver
The
kube-apiserver depends on ETCD. Stop it before restoring so that ETCD can restart cleanly.Run the ETCD restore command
When restoring from a snapshot, ETCD initializes a new cluster configuration and treats all members as new, which prevents a restored member from accidentally joining an existing cluster.
Update the ETCD configuration
Point the ETCD service at the new data directory. Use After updating the configuration file, reload and restart the service:
ps aux | grep etcd or kubectl describe pod <control-plane-pod> -n kube-system (not the etcd pod) to locate the configuration.- Systemd service
- Static pod (kubeadm)
etcd.service