kubernetes的worker节点删除后重新加入(kubeadm方式)

1.设置操作的节点不可调度及驱逐节点

kubectl cordon
kubectl drain --delete-local-data --force --ignore-daemonsets
2.删除节点
kubectl delete node
3.清空节点,清空init配置,需要删除的节点上执行

systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker
systemctl start kubelet

kubeadm reset
4.查看token,token一般24小时失效,需要重新建
kubeadm token list
kubeadm token create
kubeadm token create --print-join-command 这个命令比较靠谱
5.获取ca证书sha256编码hash值
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
5.加入节点
可以通过kubeadm token create --print-join-command获取加入的命令
kubeadm join apiserverIP:6443 --token <重新生成的token值>  --discovery-token-ca-cert-hash sha256:
00:50:56:9b:a1:ac
备注,如果节点是重复删除再添加的,还需要重置网卡信息,具体命令如下:
kubeadm reset
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker
systemctl start kubelet
kubeadm reset 

你可能感兴趣的:(k8s,kubernetes)