k8s.github.io

Practice Test - Backup and Restore Methods

Take me to Practice Test

Solutions to practice test - Backup and Restore Methods

  1. How many deployments exist in the cluster? ``` kubectl get deployments ```
  2. What is the version of ETCD running on the cluster? ``` kubectl describe pod -n kube-system etcd-controlplane ``` Find the entry for `Image`
  3. At what address can you reach the ETCD cluster from the controlplane node? ``` kubectl describe pod -n kube-system etcd-controlplane ``` Under `Command` find `--listen-client-urls`
  4. Where is the ETCD server certificate file located? On kubeadm clusters like this one, the default location for certificate files is `/etc/kubernetes/pki/etcd` Choose the correct certificate
  5. Where is the ETCD CA Certificate file located? On kubeadm clusters like this one, the default location for certificate files is `/etc/kubernetes/pki/etcd` Choose the correct certificate
  6. Take a snapshot of the ETCD database using the built-in snapshot functionality.</br>Store the backup file at location /opt/snapshot-pre-boot.db ``` ETCDCTL_API=3 etcdctl snapshot save \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key \ /opt/snapshot-pre-boot.db ```
  7. Information only.

  8. Wake up! We have a conference call! After the reboot the master nodes came back online, but none of our applications are accessible. Check the status of the applications on the cluster. What's wrong? > All of the above
  9. Luckily we took a backup. Restore the original state of the cluster using the backup file. 1. Restore the backup to a new directory ``` ETCDCTL_API=3 etcdctl snapshot restore \ --data-dir /var/lib/etcd-from-backup \ /opt/snapshot-pre-boot.db ``` 1. Modify the `etcd` pod to use the new directory. To do this, we need to edit the `volumes` section and change the `hostPath` to be the directory we restored to. ``` vi /etc/kubernetes/manifests/etcd.yaml ``` ```yaml volumes: - hostPath: path: /etc/kubernetes/pki/etcd type: DirectoryOrCreate name: etcd-certs - hostPath: path: /var/lib/etcd # <- change this type: DirectoryOrCreate name: etcd-data ``` New value: `/var/lib/etcd-from-backup` Save this and wait for up to a minute for the `etcd` pod to reload. 1. Verify ``` kubectl get deployments kubectl get services ```

See also: https://github.com/kodekloudhub/community-faq/blob/main/docs/etcd-faq.md