修改K8S Master节点IP后使用kubeadm join无法添加节点
背景: 目前接了一个需求:修改使用
kubeadm
部署好的K8S
环境所在服务器IP
。很明显,修改服务器IP
后,kube-apiserver
等服务是无法启动的。在使用脚本重新生成了apiserver
证书等一系列操作后,将所有的服务恢复后,测试使用kubeadm join
添加新的节点一直失败,看日志是kubeadm期间会使用到服务器的旧IP,调试了很久,终于发现使用旧IP的地方,以下是排查过程,记录以下,共后续参考。
一、kubeadm join
报错
旧IP: 192.168.12.110
新IP: 192.168.12.224
root@intellif-3:~# kubeadm join 192.168.12.224:6443 --token dperzp.19444xvuwd5lhr2n --discovery-token-ca-cert-hash sha256:1db95da7507bd5b509eddc7aec24d4921334a175ab5b6b2e5bde66ccc128388a --cri-socket=/run/containerd/containerd.sock
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
error execution phase preflight: unable to fetch the kubeadm-config ConfigMap: failed to get config map: Get https://192.168.12.110:6443/api/v1/namespaces/kube-system/configmaps/kubeadm-config: dial tcp 192.168.12.110:6443: i/o timeout
二、打开kubeadm
调试信息
- 在需要加入k8s集群的新服务器上执行如下命令:
kubeadm join 192.168.12.224:6443
--token dperzp.19444xvuwd5lhr2n \
--discovery-token-ca-cert-hash sha256:1db95da7507bd5b509eddc7aec24d4921334a175ab5b6b2e5bde66ccc128388a \
--cri-socket=/run/containerd/containerd.sock \
-v=10
- 输出日志如下:
I0711 15:03:41.339810 32744 join.go:367] [preflight] found NodeName empty; using OS hostname as NodeName
[preflight] Running pre-flight checks
I0711 15:03:41.339943 32744 preflight.go:90] [preflight] Running general checks
I0711 15:03:41.339987 32744 checks.go:254] validating the existence and emptiness of directory /etc/kubernetes/manifests
I0711 15:03:41.340005 32744 checks.go:292] validating the existence of file /etc/kubernetes/kubelet.conf
I0711 15:03:41.340013 32744 checks.go:292] validating the existence of file /etc/kubernetes/bootstrap-kubelet.conf
I0711 15:03:41.340021 32744 checks.go:105] validating the container runtime
I0711 15:03:41.357074 32744 checks.go:382] validating the presence of executable crictl
I0711 15:03:41.357218 32744 checks.go:341] validating the contents of file /proc/sys/net/bridge/bridge-nf-call-iptables
I0711 15:03:41.357295 32744 checks.go:341] validating the contents of file /proc/sys/net/ipv4/ip_forward
I0711 15:03:41.357340 32744 checks.go:653] validating whether swap is enabled or not
I0711 15:03:41.357385 32744 checks.go:382] validating the presence of executable ip
I0711 15:03:41.357423 32744 checks.go:382] validating the presence of executable iptables
I0711 15:03:41.357454 32744 checks.go:382] validating the presence of executable mount
I0711 15:03:41.357485 32744 checks.go:382] validating the presence of executable nsenter
I0711 15:03:41.357512 32744 checks.go:382] validating the presence of executable ebtables
I0711 15:03:41.357542 32744 checks.go:382] validating the presence of executable ethtool
I0711 15:03:41.357571 32744 checks.go:382] validating the presence of executable socat
I0711 15:03:41.357