When I want to restore the etcd back up, is it always mandatory to restore in a . . .

Madhusmita Nayak:
When I want to restore the etcd back up, is it always mandatory to restore in a new directory by giving --data-dir option or the default one? I mean ETCDCTL_API=3 etcdctl --endpoints 10.2.0.9:2379 snapshot restore snapshotdb or ETCDCTL_API=3 etcdctl snapshot restore --data-dir <data-dir-location> snapshotdb ? Can I restore it without providing --data-dir option?

Alistair Mackay:
No, it’s not mandatory, but if an exam question tells you to use a different directory, then you must do that.

You can clear out the existing /var/lib/etcd directory and then restore back to it. You should stop etcd before deleting its directory though.

If etcd is running as a pod, move its manifest file out of /etc/kubernetes/manifests so that kubelet will stop it. If running as a service (external etcd), then use systemctl to stop it.

Then delete the etcd data directory

rm -rf /var/lib/etcd

Then restore with

--data-dir /var/lib/etcd

Move the etcd manifest back into /etc/kubernetes/manifests to restart it, or use systemctl if external etcd.

Madhusmita Nayak:
okay. If I am using --data-dir <new dir> option during restore, is it necessary to stop etcd before restoring it?

Alistair Mackay:
No. However when you edit the pod manifest to point to the new directory, then kubelet will restart it on the new directory.

If it’s external etcd then you use systemctl to restart it.

Madhusmita Nayak:
okay. then teher are basically 2 things while restoring etcd back. 1) while restoring use --data-dir <new-dir> 2) update th ehostpath for etcd-data to <new-dir) to instruct etcd to use the new dir… These are teh ONLy 2 things needs to be checked right? Also it will take some time to bring the etcd pod back to normal correct?

Alistair Mackay:
We have a FAQ page on etcd here: https://github.com/kodekloudhub/community-faq/blob/main/docs/etcd-faq.md

Alistair Mackay:
For the purpose of exam, please ensure you understand both etcd backup/restore labs in the course.