kubeadm初始化k8s-删除控制节点-重新把控制节点加入集群步骤

kubeadm初始化k8s-删除控制节点-重新把控制节点加入集群步骤

# 1、把k8s-master2的信息从etcd删除:
[root@k8s-master1 ~]# tar zxvf etcd-v3.3.4-linux-amd64.tar.gz 
[root@k8s-master1 ~]# cd etcd-v3.3.4-linux-amd64
[root@k8s-master1 etcd-v3.3.4-linux-amd64]# cp etcdctl /usr/local/sbin/
[root@k8s-master1 ~]# ETCDCTL_API=3 etcdctl --endpoints 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 member list
1203cdd3ad75e761, started, k8s-master1, https://192.168.40.180:2380, https://192.168.40.180:2379
dda71d9d52b97028, started, k8s-master2, https://192.168.40.181:2380, https://192.168.40.181:2379

# 2、找到k8s-master2对应的hash值是:dda71d9d52b97028

# 3、我们下一步就是根据hash删除etcd信息,执行如下命令
[root@k8s-master1 ~]# ETCDCTL_API=3 etcdctl --endpoints 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 member remove dda71d9d52b97028

# 4、查看加入集群命令:(比较慢)
[root@k8s-master1 ~]# kubeadm token create --print-join-command
kubeadm join 192.168.40.199:16443 --token e5wrs0.lqcem5us4a04tp5x     --discovery-token-ca-cert-hash sha256:61c6754582a1ca7668770594acd1efa36a9c5c71a897517d8fb6f6c9db8ee314

# 5、把k8s-master2从k8s集群删除,重新加入到k8s步骤
[root@k8s-master1 ~]# kubectl delete nodes k8s-master2   # 可以多执行几遍
# 特别注意:在删除的节点上执行,千万不要执行错
[root@k8s-master2 ~]# kubeadm reset

# 6、把k8s-master1上的证书还是按照文档全都拷贝到k8s-master2机器上
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/ca.crt k8s-master2:/etc/kubernetes/pki/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/ca.key k8s-master2:/etc/kubernetes/pki/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/sa.key k8s-master2:/etc/kubernetes/pki/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/sa.pub k8s-master2:/etc/kubernetes/pki/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-master2:/etc/kubernetes/pki/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/front-proxy-ca.key k8s-master2:/etc/kubernetes/pki/
[root@k8s-master2 ~]# mkdir -p /etc/kubernetes/pki/etcd/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/etcd/ca.crt k8s-master2:/etc/kubernetes/pki/etcd/
[root@k8s-master1 ~]# scp /etc/kubernetes/pki/etcd/ca.key k8s-master2:/etc/kubernetes/pki/etcd/

# 7、在k8s-master2执行如下命令,把节点加入k8s集群,充当控制节点:
[root@k8s-master2 ~]# kubeadm join 192.168.40.199:16443 --token e5wrs0.lqcem5us4a04tp5x     --discovery-token-ca-cert-hash sha256:61c6754582a1ca7668770594acd1efa36a9c5c71a897517d8fb6f6c9db8ee314  --control-plane

# 8、查看集群是否加入成功:
[root@k8s-master1 ~]# kubectl get nodes
NAME          STATUS   ROLES                  AGE   VERSION
k8s-master1   Ready    control-plane,master   34m   v1.20.6
k8s-master2   Ready    control-plane,master   50s   v1.20.6
k8s-node1     Ready    <none>                 30m   v1.20.6
posted @ 2021-07-08 11:32  运维人在路上  阅读(1025)  评论(0编辑  收藏  举报