k8e集群备份与恢复

k8e集群备份与恢复

k8e主要数据目录清单

目录 描述
/var/lib/k8e/ k8e集群数据目录
/etc/k8e/ k8e集群配置目录
/var/lib/kubelet/ k8e集群容器数据目录
/usr/local/bin/ k8e 命令行文件目录

etcd数据备份与恢复

备份:

1、创建本地备份文件

[root@k8e-test-56 ~]# k8e etcd-snapshot 
INFO[2022-04-19T18:39:20.059086011+08:00] Managed etcd cluster bootstrap already complete and initialized 
W0419 18:39:20.136218    1893 warnings.go:70] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0419 18:39:20.231733    1893 warnings.go:70] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0419 18:39:20.324282    1893 warnings.go:70] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
INFO[2022-04-19T18:39:20.409032687+08:00] Saving etcd snapshot to /var/lib/k8e/server/db/snapshots/on-demand-k8e-test-56-1650364760 
{"level":"info","msg":"created temporary db file","path":"/var/lib/k8e/server/db/snapshots/on-demand-k8e-test-56-1650364760.part"}
{"level":"info","ts":"2022-04-19T18:39:20.415+0800","caller":"clientv3/maintenance.go:200","msg":"opened snapshot stream; downloading"}
{"level":"info","msg":"fetching snapshot","endpoint":"https://127.0.0.1:2379"}
{"level":"info","ts":"2022-04-19T18:39:20.476+0800","caller":"clientv3/maintenance.go:208","msg":"completed snapshot read; closing"}
{"level":"info","msg":"fetched snapshot","endpoint":"https://127.0.0.1:2379","size":"3.7 MB","took":"88.063057ms"}
{"level":"info","msg":"saved","path":"/var/lib/k8e/server/db/snapshots/on-demand-k8e-test-56-1650364760"}
INFO[2022-04-19T18:39:20.523798390+08:00] Reconciling etcd snapshot data in k8e-etcd-snapshots ConfigMap 
INFO[2022-04-19T18:39:20.535857666+08:00] Reconciliation of snapshot data in k8e-etcd-snapshots ConfigMap complete 

恢复:

1、停止k8e服务

sudo systemctl stop k8e

2、从快照中恢复主服务器

k8e server \
  --cluster-reset \
  --cluster-reset-restore-path=<PATH-TO-SNAPSHOT>

3、滚动更新其他主机上k8e服务

sudo systemctl stop k8e
rm -rf /var/lib/k8e/data
sudo systemctl start k8e

4、等待集群恢复完成