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