





























作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
Etcd 集群支持在线改变集群成员节点,可以增加、修改、删除成员节点;不过改变成员数量仍旧需要满足集群成员多数同意原则(quorum),另外请记住集群成员数量变化的影响:
注意:如果etcd 集群有故障节点,务必先删除故障节点,然后添加新节点,参考FAQ
- 1.增加 etcd 集群节点, 提高集群稳定性
- 2.增加 etcd 集群节点, 提高集群读性能(所有节点数据一致,客户端可以从任意节点读取数据)
- 3.增加 etcd 集群节点, 降低集群写性能(所有节点数据一致,每一次写入会需要所有节点数据同步)
推荐阅读:
https://github.com/easzlab/kubeasz/blob/master/docs/op/op-etcd.md
1.配置免密登录【可跳过,我们之前的环境做过】
[root@ansible99 ~]# ssh-copy-id 10.0.0.66
2.添加节点
[root@ansible99 ~]# /etc/kubeasz/ezctl add-etcd yinzhengjie-k8s 10.0.0.66
3.查看成员
[root@master231 ~]# etcdctl member list
2e038e1d3039c13f, started, etcd-10.0.0.66, https://10.0.0.66:2380 , https://10.0.0.66:2379 , false
7a9e71049ea7066e, started, etcd-10.0.0.231, https://10.0.0.231:2380 , https://10.0.0.231:2379 , false
e199235532ec8117, started, etcd-10.0.0.233, https://10.0.0.233:2380 , https://10.0.0.233:2379 , false
e440e58503cb9e47, started, etcd-10.0.0.232, https://10.0.0.232:2380 , https://10.0.0.232:2379 , false
[root@master231 ~]#
温馨提示:
生产环境中,慎用!我实际测试中的确能添加etcd节点,但是添加的过程中,又让k8s组件不正常工作了。
1.删除etcd节点
[root@ansible99 ~]# /etc/kubeasz/ezctl del-etcd yinzhengjie-k8s 10.0.0.66
2.查看etcd成员
[root@master231 ~]# etcdctl member list
7a9e71049ea7066e, started, etcd-10.0.0.231, https://10.0.0.231:2380 , https://10.0.0.231:2379 , false
e199235532ec8117, started, etcd-10.0.0.233, https://10.0.0.233:2380 , https://10.0.0.233:2379 , false
e440e58503cb9e47, started, etcd-10.0.0.232, https://10.0.0.232:2380 , https://10.0.0.232:2379 , false
[root@master231 ~]#
温馨提示:
删除etcd节点过程中,也会让集群短暂时间不可用,因为它需要修改api-server的配置信息。
1.查看现有的备份数据【如果你之前从来没有备份过,是看不到备份数据的】
[root@ansible99 ~]# ll /etc/kubeasz/clusters/yinzhengjie-k8s/backup/
total 11952
drwxr-xr-x 2 root root 4096 Jun 4 03:30 ./
drwxr-xr-x 5 root root 4096 Jun 5 01:49 ../
-rw------- 1 root root 6111264 Jun 4 03:30 snapshot_202606040330.db
-rw------- 1 root root 6111264 Jun 4 03:30 snapshot.db
[root@ansible99 ~]#
2.备份etcd集群数据
[root@ansible99 ~]# /etc/kubeasz/ezctl backup yinzhengjie-k8s
3.再次查看备份数据
[root@ansible99 ~]# ll /etc/kubeasz/clusters/yinzhengjie-k8s/backup/
total 17924
drwxr-xr-x 2 root root 4096 Jun 5 01:51 ./
drwxr-xr-x 5 root root 4096 Jun 5 01:49 ../
-rw------- 1 root root 6111264 Jun 4 03:30 snapshot_202606040330.db
-rw------- 1 root root 6111264 Jun 5 01:51 snapshot_202606050151.db
-rw------- 1 root root 6111264 Jun 5 01:51 snapshot.db
[root@ansible99 ~]#
1.删除etcd数据
[root@master231 ~]# kubectl get deploy,svc,po
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/yinzhengjie-app01 3/3 3 3 23h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 40h
NAME READY STATUS RESTARTS AGE
pod/yinzhengjie-app01-9c78ddbdc-47qfl 1/1 Running 1 (14h ago) 23h
pod/yinzhengjie-app01-9c78ddbdc-9c57t 1/1 Running 1 (14h ago) 23h
pod/yinzhengjie-app01-9c78ddbdc-g9cn5 1/1 Running 1 (14h ago) 23h
[root@master231 ~]#
[root@master231 ~]# kubectl delete deployments.apps yinzhengjie-app01
deployment.apps "yinzhengjie-app01" deleted
[root@master231 ~]#
[root@master231 ~]# kubectl get deploy,svc,po
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 40h
[root@master231 ~]#
2.恢复数据
[root@ansible99 ~]# /etc/kubeasz/ezctl restore yinzhengjie-k8s
3.测试验证
[root@master231 ~]# kubectl get deploy,svc,po
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/yinzhengjie-app01 3/3 3 3 24h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 41h
NAME READY STATUS RESTARTS AGE
pod/yinzhengjie-app01-9c78ddbdc-47qfl 1/1 Running 0 24h
pod/yinzhengjie-app01-9c78ddbdc-9c57t 1/1 Running 0 24h
pod/yinzhengjie-app01-9c78ddbdc-g9cn5 1/1 Running 0 24h
[root@master231 ~]#
温馨提示:
恢复数据的时候,也会停止集群哟,要注意这个细节,生产环境慎用!
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。