K8s 节点修改ip

Kubernetes / 2022-11-22

master

/etc/hosts
grep -r “10.20.13.5” /etc/kubernetes | awk -F ‘:’ ‘{print $1}’ | uniq |xargs -I sed -I ’s/10.20.13.50/10.20.11.50/g’ {}
grep -r “10.20.13.5” $HOME | awk -F ‘:’ ‘{print $1}’ | uniq |xargs -I sed -I ’s/10.20.13.50/10.20.11.50/g’ {}
mv $HOME/.kube/cache/discovery/10.20.13.50_6443  $HOME/.kube/cache/discovery/10.20.11.50_6443

cd /etc/kubernetes
rm -f admin.conf kubelet.conf controller-manager.conf scheduler.conf
kubeadm init phase kubeconfig all

kubeadm init phase certs all --apiserver-advertise-address=10.20.11.50
kubeadm alpha phase certs apiserver-kubelet-client
kubeadm alpha phase certs front-proxy-client

mv /etc/kubernetes/pki/apiserver.key /etc/kubernetes/pki/apiserver.key.old
mv /etc/kubernetes/pki/apiserver.crt /etc/kubernetes/pki/apiserver.crt.old
mv /etc/kubernetes/pki/apiserver-kubelet-client.crt /etc/kubernetes/pki/apiserver-kubelet-client.crt.old
mv /etc/kubernetes/pki/apiserver-kubelet-client.key /etc/kubernetes/pki/apiserver-kubelet-client.key.old
mv /etc/kubernetes/pki/front-proxy-client.crt /etc/kubernetes/pki/front-proxy-client.crt.old
mv /etc/kubernetes/pki/front-proxy-client.key /etc/kubernetes/pki/front-proxy-client.key.old

node

/etc/hosts
grep -r "10.20.13.5" /etc/kubernetes | awk -F ':' '{print $1}' | uniq |xargs -i sed -i 's/10.20.13.50/10.20.11.50/g' {}
grep -r "10.20.13.5" $HOME | awk -F ':' '{print $1}' | uniq |xargs -i sed -i 's/10.20.13.50/10.20.11.50/g' {}