1. 程式人生 > >將有問題的etcd節點重新加入叢集

將有問題的etcd節點重新加入叢集

etcd叢集中某個節點壞掉,或不小心清空了某個節點的資料,可以按照如下步驟重新將此節點加入叢集

1.從叢集中刪除壞掉的節點

1.檢視叢集健康狀態,找到壞掉的節點ID:

etcdctl --endpoints=https://10.4.63.161:2379 --ca-file=/etc/ssl/etcd/ssl/ca.pem --cert-file=/etc/ssl/etcd/ssl/node-k8smaster02.pem --key-file=/etc/ssl/etcd/ssl/node-k8smaster02-key.pem  cluster-health

2.將此節點從叢集中移除

etcdctl --endpoints=https:
//10.4.63.161:2379 --ca-file=/etc/ssl/etcd/ssl/ca.pem --cert-file=/etc/ssl/etcd/ssl/node-k8smaster02.pem --key-file=/etc/ssl/etcd/ssl/node-k8smaster02-key.pem member remove 6284d00a680a6741

2. 修改壞掉節點的配置檔案

vim /etc/etcd.env

ETCD_DATA_DIR=/dcos/etcd
ETCD_ADVERTISE_CLIENT_URLS=https://10.4.63.160:2379
ETCD_INITIAL_ADVERTISE_PEER_URLS
=https://10.4.63.160:2380 ETCD_INITIAL_CLUSTER_STATE=existing ------------------------修改,從new改為existing ETCD_LISTEN_CLIENT_URLS=https://10.4.63.160:2379,https://127.0.0.1:2379 ETCD_ELECTION_TIMEOUT=5000 ETCD_HEARTBEAT_INTERVAL=250 ETCD_INITIAL_CLUSTER_TOKEN=k8s_etcd ETCD_LISTEN_PEER_URLS=https://10.4.63.160:2380 ETCD_NAME
=etcd1 ETCD_PROXY=off ETCD_INITIAL_CLUSTER=etcd1=https://10.4.63.160:2380,etcd2=https://10.4.63.161:2380,etcd3=https://10.4.63.162:2380 # TLS settings ETCD_TRUSTED_CA_FILE=/etc/ssl/etcd/ssl/ca.pem ETCD_CERT_FILE=/etc/ssl/etcd/ssl/member-k8smaster01.pem ETCD_KEY_FILE=/etc/ssl/etcd/ssl/member-k8smaster01-key.pem ETCD_PEER_TRUSTED_CA_FILE=/etc/ssl/etcd/ssl/ca.pem ETCD_PEER_CERT_FILE=/etc/ssl/etcd/ssl/member-k8smaster01.pem ETCD_PEER_KEY_FILE=/etc/ssl/etcd/ssl/member-k8smaster01-key.pem ETCD_PEER_CLIENT_CERT_AUTH=true

3.將此節點作為新成員新增入叢集

etcdctl --endpoints=https://10.4.63.161:2379 --ca-file=/etc/ssl/etcd/ssl/ca.pem --cert-file=/etc/ssl/etcd/ssl/node-k8smaster02.pem --key-file=/etc/ssl/etcd/ssl/node-k8smaster02-key.pem  member add etcd1 https://10.4.63.160:2380

4.重啟壞掉的節點

systemctl restart etcd