备份
从镜像中拷贝etcdctl二进制命令
[root@k8s1 ~]# docker run -it --rm reg.westos.org/k8s/etcd:3.5.6-0 sh
输入ctrl+pq快捷键,把容器打入后台
获取容器id
[root@k8s1 ~]# docker ps
从容器拷贝命令到本机
docker container cp c7e28b381f07:/usr/local/bin/etcdctl /usr/local/bin
[root@k8s1 ~]# which etcdctl
删除容器
[root@k8s1 ~]# docker rm -f c7e28b381f07
备份
[root@k8s1 ~]# ETCDCTL_API=3 etcdctl --endpoints 192.168.92.12:2379 --cert=/root/etcd/server.crt --key=/root/etcd/server.key --cacert=/root/etcd/ca.crt snapshot save /root/etcd/snapshotdb
查看快照状态
[root@k8s1 ~]# ETCDCTL_API=3 etcdctl --endpoints 192.168.92.12:2379 --cert=/root/etcd/server.crt --key=/root/etcd/server.key --cacert=/root/etcd/ca.crt --write-out=table snapshot status /root/etcd/snapshotdb
删除集群资源
[root@k8s2 helm]# helm uninstall myapp
[root@k8s2 helm]# kubectl get pod
恢复
停止所有核心组件
[root@k8s2 pki]# cd /etc/kubernetes/manifests/
[root@k8s2 manifests]# ls
[root@k8s2 manifests]# mv * /mnt/
移除yaml文件后对应容器自动停止
[root@k8s2 manifests]# crictl ps
从快照恢复
[root@k8s2 manifests]# cd /var/lib/etcd/
[root@k8s2 etcd]# ls
[root@k8s2 etcd]# mv member/ /tmp/
[root@k8s2 etcd]# ETCDCTL_API=3 etcdctl snapshot restore --data-dir /var/lib/etcd/ /tmp/snapshotdb
[root@k8s2 etcd]# ls
重启所有组件
[root@k8s2 etcd]# cd /etc/kubernetes/manifests/
[root@k8s2 manifests]# mv /mnt/* .
yaml文件移动回来后容器自动启动
[root@k8s2 manifests]# crictl ps
所有集群节点重启kubelet服务
[root@k8s2 manifests]# reboot
[root@k8s3 ~]# reboot
[root@k8s4 ~]# reboot
看到pod恢复表示成功
[root@k8s2 ~]# kubectl get pod