背景
1 台 master 加入集群后发现忘了修改主机名,而在 k8s 集群中修改节点主机名非常麻烦,不如将 master 退出集群改名并重新加入集群(前提是用的是高可用集群)。
操作步骤
ssh 登录另外一台 master 节点将要改名的 master 节点移出集群。
kubectl drain blog-k8s-n0
kubectl delete node blog-k8s-n0
登录已退出集群的 master 服务器重置 kubelet 配置并重新加入集群。
kubeadm reset
kubeadm join k8s-api:6443 --token ****** --discovery-token-ca-cert-hash ****** --control-plane --certificate-key ****** --v=5
加入失败,错误信息如下:
I0109 21:26:48.440711 3893 etcd.go:107] etcd endpoints read from pods: https://10.0.1.81:2379,https://10.0.1.32:2379,https://10.0.1.33:2379
I0109 21:26:48.455921 3893 etcd.go:166] etcd endpoints read from etcd: https://10.0.1.81:2379,https://10.0.1.32:2379,https://10.0.1.33:2379
I0109 21:26:48.455975 3893 etcd.go:125] update etcd endpoints: https://10.0.1.81:2379,https://10.0.1.32:2379,https://10.0.1.33:2379
I0109 21:27:08.469938 3893 etcd.go:388] Failed to get etcd status for https://10.0.1.81:2379: failed to dial endpoint https://10.0.1.81:2379 with maintenance client: context deadline exceeded
failed to dial endpoint https://10.0.1.81:2379 with maintenance client: context deadline exceeded
etcd cluster is not healthy
从错误信息看 etcd 集群不知道 10.0.1.81 已经退出 k8s 集群,etcd 集群中还保存着 10.0.1.81 的信息,所以在加入时连接 10.0.1.81 失败。
登录其中一台正常的 master ,进入 etcd 容器:
docker exec -it $(docker ps -f name=etcd_etcd -q) /bin/sh
查看 etcd 集群的成员列表,果然其中还有那台已经退出集群的服务器 blog-k8s-n0
$ 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
12637f5ec2bd02b8, started, blog-k8s-n0, https://10.0.1.81:2380, https://10.0.1.81:2379, false
17d58f8d29164d23, started, k8s-master1, https://10.0.1.32:2380, https://10.0.1.32:2379, false
19441808830db070, started, k8s-master2, https://10.0.1.33:2380, https://10.0.1.33:2379, false
在容器中将这台服务器从 etcd 集群中移除
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 12637f5ec2bd02b8
移除之后之前退出集群的服务器就能成功加入集群。
原文地址:https://www.cnblogs.com/dudu/p/12173867.html
时间: 2024-11-14 17:13:07