集群node剔除和加入

集群node剔除和加入

Scroll Down

集群中剔除node

#驱逐node节点上的服务
[root@k8s02 ~]# kubectl drain nodename --delete-local-data --force --ignore-daemonsets
#删除node
[root@k8s02 ~]# kubectl delete node nodename

集群中加入node

node之前反复添加过,添加之前需要清除下网络,在node上执行如下操作

重启kubernets服务,重置网络,删除网络配置,link
[root@k8s02 ~]# kubeadm reset
[root@k8s02 ~]# systemctl stop kubelet
[root@k8s02 ~]# systemctl stop docker
[root@k8s02 ~]# rm -rf /var/lib/cni/
[root@k8s02 ~]# rm -rf /var/lib/kubelet/*
[root@k8s02 ~]# rm -rf /etc/cni/
[root@k8s02 ~]# ifconfig cni0 down
[root@k8s02 ~]# ifconfig flannel.1 down
[root@k8s02 ~]# ifconfig docker0 down
[root@k8s02 ~]# ip link delete cni0
[root@k8s02 ~]# ip link delete flannel.1
[root@k8s02 ~]# systemctl start docker
[root@k8s02 ~]# systemctl start kubelet

获取master的join token,加入集群

#创建token
[root@k8s01 ~]# kubeadm token create
waggjc.0ml9hmrf946wrbai
#列出token
[root@k8s01 ~]# kubeadm token list
TOKEN                     TTL         EXPIRES                     USAGES                   DESCRIPTION   EXTRA GROUPS
waggjc.0ml9hmrf946wrbai   23h         2020-03-07T12:28:01+08:00   authentication,signing   <none>        system:bootstrappers:kubeadm:default-node-token
#获取token值
[root@k8s01 ~]# kubeadm token list  | awk -F" " '{print $1}' |tail -n 1
waggjc.0ml9hmrf946wrbai
#获取CA公钥的哈希值
[root@k8s01 ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed  's/^ .* //'
(stdin)= d9390c6fe15ba10d46835c58682a2c627c91d21f87249a7bdb49d61857786e80
#重新加入节点
[root@k8s02 ~]# kubeadm join 192.168.200.135:6443 --token waggjc.0ml9hmrf946wrbai     --discovery-token-ca-cert-hash sha256:d9390c6fe15ba10d46835c58682a2c627c91d21f87249a7bdb49d61857786e80  --ignore-preflight-errors=all
 
[root@k8s02 ~]# kubectl get node
NAME                 STATUS   ROLES    AGE    VERSION
k8s01.axhome.local   Ready    master   143d   v1.15.4
k8s02.axhome.local   Ready    <none>   12s    v1.15.4
k8s03.axhome.local   Ready    master   143d   v1.15.4
k8s04.axhome.local   Ready    <none>   126d   v1.15.4
k8s05.axhome.local   Ready    <none>   128d   v1.15.4
k8s06.axhome.local   Ready    master   143d   v1.15.4
k8s07.axhome.local   Ready    <none>   128d   v1.15.4
k8s08.axhome.local   Ready    <none>   23d    v1.15.4

参考链接:https://www.cnblogs.com/wangxu01/articles/11803547.html