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
作者:Lawrence
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
扫描上面二维码关注我
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.