[k8s] Backup & Restore ============= ###### tags: `kubernetes` `cluster maintenance` ![](https://i.imgur.com/RwTWLRz.png) ## Backup "Resource Configuration" ![](https://i.imgur.com/MMgCwnn.png) ## Backup ETCD ![](https://i.imgur.com/WRSjQ2w.png) ```shell= ETCDCTL_API=3 etcdctl snapshot save \ --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 \ /opt/snapshot-pre-boot.db ``` ## Restore ETCD ![](https://i.imgur.com/10wqUxE.png) ```shell= ETCDCTL_API=3 etcdctl snapshot restore \ --data-dir /var/lib/etcd-from-backup \ /opt/snapshot-pre-boot.db ``` #### edit etcd.yaml ```yaml= volumes: - hostPath: path: /var/lib/etcd-from-backup type: DirectoryOrCreate name: etcd-data ``` > Note 1: As the ETCD pod has changed it will automatically restart, and also ==**kube-controller-manager**== and ==**kube-scheduler**==. Wait 1-2 to mins for this pods to restart. You can run the command: `watch "crictl ps | grep etcd"` to see when the ETCD pod is restarted.