零、准备工作
find / -name etcdctl
cp /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/12/fs/usr/local/bin/etcdctl /usr/local/bin/etcdctl
alias ec="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"
ec endpoint status member list --cluster
一、etcdctl defrag
ec defrag
ks exec -it $(ks get pod | grep etcd | awk 'NR==1 {print $1}') sh
alias ec="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"
ec endpoint status --cluster -w table
ec defrag
ec endpoint status --cluster -w table
ec !
遇事不要慌,先深呼吸一下。
1、关闭etcd
mv /etc/kubernetes/manifests/etcd.yaml .
2、etcdctl defrag
etcdctl defrag --data-dir /opt/qfusion/etcd
3、启动etcd
mv etcd.yaml /etc/kubernetes/manifests/etcd.yaml
4、查看etcd服务
ec endpoint status member list --cluster
nerdctl ps -a |grep etcd
二、剔除etcd
1、member remove
ec member remove <memberID>
2、移除配置
mv /etc/kubernetes/manifests/etcd.yaml .
3、移除etcd数据目录
mv /opt/qfusion/etcd /opt/qfusion/etcd_bak
三、添加etcd
1、在正常的节点上操作,假如etcd节点
ec member add 10-10-180-15 --peer-urls=https://10.10.180.15:2380
2、启动etcd
- --initial-cluster=10-10-180-15=https://10.10.180.15:2380,10-10-180-8=https://10.10.180.8:2380,10-10-180-9=https://10.10.180.9:2380 #加入etcd集群的时候需要补全集群信息,否则etcd会报 member count is unequal 的错误而无法成功启动- --initial-cluster-state=existing # 以加入etcd集群的方式启动etcd
initial-cluster-state=new # 以新建etcd集群的方式启动etcd