1.修改物理机主机名
hostnamectl set-hostname <hostname>
2.修改 /etc/kubernetes/manifests 目录下的文件,将文件内容包含旧主机名的修改为新主机名,修改2处地方
cd /etc/kubernetes/manifests
vi etcd.yaml
3.导出节点配置文件,编辑配置,把文件中旧主机名替换为新主机名,文件修改4处地方
(注:如labels: 中没有node-role.kubernetes.io/master: "",可以手动添加(用于标识节点名称)
kubectl get node <old-nodeName> -o yaml > node.yaml
4. 修改 kube-system 命名空间下的 kubeadm-config ConfigMap。将其中的旧主机名修改为新主机名,修改1处地方
kubectl -n kube-system edit configmap kubeadm-config
5.为新主机名生成证书,替换原来的证书文件
注意:cp复制过程中如果需要强制覆盖,加-f即可
cd /etc/kubernetes/pki/
mkdir -p ~/tmp/BACKUP_etc_kubernetes_pki/etcd/
mv apiserver.crt apiserver-etcd-client.key apiserver-kubelet-client.crt front-proxy-ca.crt front-proxy-client.crt front-proxy-client.key front-proxy-ca.key apiserver-kubelet-client.key apiserver.key apiserver-etcd-client.crt ~/tmp/BACKUP_etc_kubernetes_pki/.
mv etcd/healthcheck-client.* etcd/peer.* etcd/server.* ~/tmp/BACKUP_etc_kubernetes_pki/etcd/
kubeadm init phase certs all
cd /etc/kubernetes
mkdir -p ~/tmp/BACKUP_etc_kubernetes
mv admin.conf controller-manager.conf kubelet.conf scheduler.conf ~/tmp/BACKUP_etc_kubernetes/.
kubeadm init phase kubeconfig all
mkdir -p ~/tmp/BACKUP_home_.kube
cp -r ~/.kube/* ~/tmp/BACKUP_home_.kube/.
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
6. 应用第三步修改过的节点配置文件
kubectl apply -f node.yaml
7.查看当前节点名称,并移除原来主机名对应的节点
kubectl get nodes
kubectl delete node <old-noname>
8.重启 kubelet 和 docker 服务
systemctl daemon-reload && systemctl restart kubelet && systemctl restart docker
(转发请注明出处:http://www.cnblogs.com/zhangyongli2011/ 如发现有错,请留言,谢谢)