[k8s] Backup & Restore
=============
###### tags: `kubernetes` `cluster maintenance`

## Backup "Resource Configuration"

## Backup ETCD

```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

```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.