Hi, in the MOCK Exam-2 , we do etcd backup and when I tried to restore from that . . .

Esra:
Hi, in the MOCK Exam-2 , we do etcd backup and when I tried to restore from that back up. I lost all cluster. The commands I run:
controlplane $ 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-backup.db
controlplane $ ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd-backup.db --data-dir=/var/lib/etcd10

I have edited also etcd.yaml:

  • command:
    • etcd
    • –advertise-client-urls=https://172.17.0.23:2379
    • –cert-file=/etc/kubernetes/pki/etcd/server.crt
    • –client-cert-auth=true
    • –data-dir=/var/lib/etcd10
      volumeMounts:
    • mountPath: /var/lib/etcd10
      name: etcd-data
    • mountPath: /etc/kubernetes/pki/etcd
      name: etcd-certs
      hostNetwork: true
      priorityClassName: system-node-critical
      volumes:
  • hostPath:
    path: /etc/kubernetes/pki/etcd
    type: DirectoryOrCreate
    name: etcd-certs
  • hostPath:
    path: /var/lib/etcd10

What I am missing there?

Gurudutt Dongre:
–data-dir=/var/lib/etcd10 –> This should remain /var/lib/etcd as this is the directory which is within the container. You dont need to change that. You only need to change the -hostPath and point it to the new location.

Basavraj Nilkanthe:
Yes

Basavraj Nilkanthe:
If you want to change --data-dir from container… Make sure you are changing in two location 1- inside command and 2-update volumeMounts path… But this is really not required

Basavraj Nilkanthe:
Just updating volume hostPath should be enough

Basavraj Nilkanthe:
If you face issue… Try to restart etcd

Basavraj Nilkanthe:
Pod

Esra:
@Basavraj Nilkanthe @Gurudutt Dongre Do you mean “ETCDCTL_API=3 etcdctl snapshot restore /opt/etcd-backup.db” is sufficient to restore? If I do not specify any new data dir, what am I supposed to change in hostPath?

Esra:
and there are several threads related etcd backup and restore but still not clear steps when it is needed to use long version " ETCDCTL_API=3 etcdctl --endpoints=https://[127.0.0.1]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt _
–name=master
–cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key
–data-dir /var/lib/etcd-from-backup
–initial-cluster=master=https:
//127.0.0.1:2380 _
–initial-cluster-token etcd-cluster-1
–initial-advertise-peer-urls=https:_//127.0.0.1:2380 _
snapshot restore /tmp/snapshot-pre-boot.db" and how it should be from master node and how it should be from student node? someone says you need to scp to master after you backup? There is no clear guidance on that or I can not find it. Appreciate if you share some link that helps clarifying this questions.

Basavraj Nilkanthe:
Well. You have to pass --data-dir parameter while restoring and certs can be ignored…

Basavraj Nilkanthe:
In order to not create conflict between existing etcd data and new backup data… You have to use --data-dir

Esra:
@Basavraj Nilkanthe ok I have to use --data-dir for restore command, right? and it should be different then /var/lib/etcd, right? It could be --data-dir /var/lib/etcd-from-backup for example. Right? Thanks for support.

Basavraj Nilkanthe:
Yes

Basavraj Nilkanthe:
As this is filesytem on nodes so you have to update volumes hostpath in your etcd.yaml file

Basavraj Nilkanthe:
So that etcd will start referring new data directory

Basavraj Nilkanthe:
This is important after restore