etcd备份与恢复
- 创建备份目录mkdir /var/lib/etcd_backup
- 从etcd中的一个正常节点上备份etcd数据
ETCDCTL_API=3 /opt/etcd/bin/etcdctl \
--cacert=/opt/etcd/ssl/ca.pem \
--cert=/opt/etcd/ssl/server.pem \
--key=/opt/etcd/ssl/server-key.pem \
--endpoints=https://192.168.113.4:2379 \
snapshot save /var/lib/etcd_backup/etcd_20230616.db
- 停止所节点的kube-apiserver和etcd
systemctl stop kube-apiserver && systemctl stop etcd
- 备份原始etcd的路径中的文件
mv /var/lib/etcd/default.etcd /var/lib/etcd/default.etcd_bak
- 所有节点恢复etcd数据库
master01执行{etcd01节点}
ETCDCTL_API=3 /opt/etcd/bin/etcdctl snapshot restore /var/lib/etcd_backup/etcd_20230616.db --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --name etcd-1 --initial-cluster "etcd-1=https://192.168.113.4:2380,etcd-2=https://192.168.113.6:2380,etcd-3=https://192.168.113.5:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls https://192.168.113.4:2380 --data-dir=/var/lib/etcd/default.etcd
work01执行{etcd02节点}
ETCDCTL_API=3 /opt/etcd/bin/etcdctl snapshot restore /var/lib/etcd_backup/etcd_20230616.db --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --name etcd-3 --initial-cluster "etcd-1=https://192.168.113.4:2380,etcd-2=https://192.168.113.6:2380,etcd-3=https://192.168.113.5:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls https://192.168.113.5:2380 --data-dir=/var/lib/etcd/default.etcd
work02执行{etcd03节点}文章来源:https://www.toymoban.com/news/detail-509712.html
ETCDCTL_API=3 /opt/etcd/bin/etcdctl snapshot restore /var/lib/etcd_backup/etcd_20230616.db --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --name etcd-2 --initial-cluster "etcd-1=https://192.168.113.4:2380,etcd-2=https://192.168.113.6:2380,etcd-3=https://192.168.113.5:2380" --initial-cluster-token etcd-cluster --initial-advertise-peer-urls https://192.168.113.6:2380 --data-dir=/var/lib/etcd/default.etcd
- 为目录赋予权限
- 每个节点启动etcd
systemctl start etcd
- 查看状态
ETCDCTL_API=3 /opt/etcd/bin/etcdctl \
--cacert=/opt/etcd/ssl/ca.pem \
--cert=/opt/etcd/ssl/server.pem \
--key=/opt/etcd/ssl/server-key.pem \
--endpoints=https://192.168.113.4:2379,https://192.168.113.6:2379,https://192.168.113.5:2379 \
endpoint health --write-out=table
- 启动kubeapi-server
systemctl start kube-apiserver
10.查看k8s集群状态文章来源地址https://www.toymoban.com/news/detail-509712.html
kubectl get cs
到了这里,关于k8s集群中etcd的备份与恢复的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!