官方文档有关这题的资料如下
https://kubernetes.io/zh-cn/docs/tasks/administer-cluster/configure-upgrade-etcd/

基于上述方式进行验证 未能成功。 总结成功的方式如下:
关键两步:
1、恢复时 利用--data-dir="/var/lib/etcd" 将数据库文件还原至原来位置。
2、通过重命名/etc/kubernetes/manifests 下etcd 文件,重启使配置生效。
** mv etcd.yaml.b etcd.yaml**
** mv etcd.yaml etcd.yaml.b**

etcd 还原操作
root@K8sMaster:~# alias etcdctl=' ETCDCTL_API=3 etcdctl --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 '
#查看当前etcd 数据库内容
root@K8sMaster:~# etcdctl get /registry/key1
root@K8sMaster:~# etcdctl get /registry/key2
/registry/key2
value2
#恢复前 将etcd、api停⽌了,移动静态pod⽂件后,过了⼀会容器会⾃动停⽌
root@K8sMaster:~# mv /etc/kubernetes/manifests /etc/kubernetes/manifests.bak
#删除文件默认指向的文件位置,用于恢复
root@K8sMaster:~# mv /var/lib/etcd /var/lib/etcd.bak
root@K8sMaster:~#  ETCDCTL_API=3 etcdctl --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    snapshot restore /var/lib/backup/etcd-snapshot.db **--data-dir="/var/lib/etcd"******
2022-06-19 01:37:51.132639 I | mvcc: restore compact to 18299
2022-06-19 01:37:51.167154 I | etcdserver/membership: added member 8e9e05c52164694d [http://localhost:2380] to cluster cdf818194e3a8c32
root@K8sMaster:~# mv /etc/kubernetes/manifests.bak /etc/kubernetes/manifests
root@K8sMaster:~# etcdctl get /registry/key1
/registry/key1
value1
root@K8sMaster:~# etcdctl get /registry/key2
root@K8sMaster:~#


posted on 2022-06-19 02:35  vmsky  阅读(232)  评论(0编辑  收藏  举报