1.把/etc/kubernetes/*.conf中所有的旧ip换成新ip
shell
cd /etc/kubernetes/
find . -type f | xargs sed -i "s/$oldip/$newip/"
2.替换$HOME/.kube/config文件中的旧ip为新ip(注意sudo的话需要改root下的)
shell
cd $HOME/.kube/
find . -type f | xargs sed -i "s/$oldip/$newip/"
3.修改$HOME/.kube/cache/discovery/ 下的文件夹名改成新的ip
shell
cd $HOME/.kube/cache/discovery/
mv old_ip_6443 new_ip_6443
4.重新生成证书
shell
cd /etc/kubernetes/pki
rm -rf apiserver.key
rm -rf apiserver.srt
kubeadm init phase certs apiserver --apiserver-advertise-address newIP
5.编辑 ConfigMap,将旧 IP 替换成新的 IP
shell
kubectl -n kube-system edit cm kubeadm-config
kubectl -n kube-system edit cm kube-proxy
kubectl edit cm -n kube-system coredns
kubectl edit cm -n kube-public cluster-info
6.修改/etc/hosts文件将老的ip换成新的ip
shell
vim /etc/hosts
:%s/old_ip/new_ip/
最后重启服务器就可以了。