Question 3: First, create a snapshot of the existing etcd instance running at https://127.0.0.1:2379, saving the snapshot to /var/lib/etcd-snapshot123.db
After that, you need to restore an existing / previous snapshot located at /var/lib/etcd-snapshot-previous.db.
solution:
First, we need to identify the etcd pods. Below command we can use.
kubectl -n kube-system get pod | grep etcd
Now, we need to identify the CA Cert, Cert and Server key. Below command, we can use.
kubectl -n kube-system describe pod etcd-master1.example.com
Once, we have all details, we can take the snapshot.
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-snapshot123.db
We can also verify the new file.
ls -l /opt/etcd-backup.db
How to restore from backup file (/var/lib/from-backup) ?
Restore the backup in "/var/lib/from-backup"
directory. Make sure to
use sudo before running command otherwise it will throw permission issue
sudo etcdctl snapshot restore –data-dir /var/lib/from-backup /var/lib/etcd-snapshot-previous.db
Or we can use below command.
sudo etcdctl snapshot restore --data-dir /var/lib/from-backup --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
/var/lib/etcd-snapshot-previous.db
sudo chown -R etcd:etcd /var/lib/etcd
sudo systemctl start etcd
All explanation is being done on this video : https://youtu.be/0gkKak8ERQM