In this blog, we will see how to backup and restore etcd on the kubeadm cluster.
How to Backup ETCD on the Kubeadm Cluster
First, let’s see how to take backup of etcd, follow the below steps to backup etcd.
To take a backup of etcd you need etcdctl installed in your controller node, to install etcdctl run the below command
sudo apt install etcd-client
Once you installed etcdctl, run the below command to take a backup of etcd.
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
--cacert=<trusted-ca-file-location> \
--cert=<cert-file-location> \
--key=<key-file-location> \
snapshot save <backup-file-location>
To get the locations of files specified in the above command check the etcd manifest file, to view the etcd manifest file use the command given below
cat /etc/kubernetes/manifests/etcd.yaml
By using the file location from the above file, my command will be
ETCDCTL_API=3 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/etcd.db
/opt/etcd.db is the location where I specify to store the snapshot.
By running the backup command, you will get the following output
Verify the snapshot using the command
ETCDCTL_API=3 etcdctl --write-out=table snapshot status /opt/etcd.db
You will get the following output
How to Restore ETCD Backup on the Kubeadm Cluster
To restore the backup etcd snapshot run the following command
ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd.db
/opt/etcd.db is the location of my snapshot, this command will restore the etcd on the default location. By running the restore command you will get the following output
You can also specify the data directory where you want to restore etcd, the command to restore etcd in a specific data director is given below
ETCDCTL_API=3 etcdctl --data-dir /opt/etcd snapshot restore /opt/etcd.db
/opt/etcd is the data directory where I am restoring etcd.
Conclusion
In summary, we have learned about how to take backup and restore on Kubernetes.
I believe this blog has given a decent understanding of taking backups and restoring on Kubernetes.