Hello Leaders, I am back with another topic. Today we will learn about etcd Kubernetes snapshot. Actually, etcd is a database for Kubernetes and it stops all the data of Kubernetes. So today we will see how we can take a snapshot of the etcd and how to restore this in Kubernetes.
Basically, Etcd is a very important part of Kubernetes. Etcd stores the all details like an object, its state, and cluster configurations. It is a consistent and distributed and secure key-value store. It works on the raft protocol. You can also look into Kubernetes architecture.
Basically, We will use etcdctl command line utility to take a snapshot of data.etcd has its own built-in snapshot mechanism.etcdctl is the command line utility that interacts with etcd for snapshots.
I have divided the process into steps. You can follow the below step to take the backup.
Step1: You need to login into your control plane or master node from where you manage the other worker nodes.
In my case I am using minikube so I can log in to minikube master node using the below command:
Step2: In your master node, you should check the etcdcli command line utility. If it is not installed then use the below command to install it into your master node.
sudo apt install etcd-client
Step3: To take the backup we need a few values. These values are below:
- Etcd endpoint
- Server key
- Server certificate
- Cacert certificate
We have two options to find all the details in two ways.
1. You can log in to the master node and run the below command and get the details:
sudo cat /etc/kubernetes/manifests/etcd.yaml
2. You can get the all details without login into the master node. You can just follow the below command.
Kubectl get pods -n kube-system
Now you will get the pods related to etcd. Copy that pod name and run the below command:
Kubectl describe pods <paste here> -n kube-system
Step4: it’s time to take a snapshot of the etcd. You can run the below command to take the backup:
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=<ca-file> --cert=<cert-file> --key=<key-file> snapshot save <backup-file-location>
After passing the file name your command will look like the below command:
ETCDCTL_API=3 etcdctl --endpoints=https://192.168.49.2:2379 \ --cacert=/var/lib/minikube/certs/etcd/ca.crt \ --cert=/var/lib/minikube/certs/etcd/server.crt \ --key=/var/lib/minikube/certs/etcd/server.key \ snapshot save /home/knoldus/Desktop/knoldus/test_space/etcd.db
Step5: Verify the snapshot using the following command:
ETCDCTL_API=3 etcdctl --write-out=table snapshot status /opt/backup/etcd.db
Restore the etcd using a snapshot
Step6: run the below command to restore.
ETCDCTL_API=3 etcdctl snapshot restore /opt/backup/etcd.db
In this blog, We learned about the etcd backup and restore using etcdctl command line utility. You can subscribe to the knoldus to get more blogs. One more thing, We are happy to announce that we have launched our course. You can check out that and enroll in any course. Thank you ..