k8s delete node node

1. Delete node node

1. First check the nodes information on this node.

kubectl get nodes

2. Evict the pod on this node

kubectl drain node01 --delete-local-data --force --ignore-daemonsets

3. Delete this node node

kubectl delete nodes node01

4. Then execute the following command on the node01 node:

 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

If you do not do the above operations, the pod on this node will fail to start. The specific error message is: networkPlugin cni failed to set up pod "alertmanager-main-1_monitoring" network: failed to set bridge ad has an IP address different from 10.244 .5.1/24, which means that the cluster network cni already has a network address different from 10.244.51.1/24, so you need to execute the above command to reset the node network.


2. Rejoin this node node

The command format for nodes to join the cluster: kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>

The default token validity period is 24 hours. After expiration, the token is unavailable. The solution is as follows:

Regenerate new token ==> kubeadm token create 

1. View the current token list

kubeadm token list

2. Regenerate a new token

kubeadm token create

3. View the current token list again

kubeadm token list

4. Obtain the sha256 encoded hash value of the ca certificate

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'

5. Node joins the cluster

kubeadm join 39.96.46.96:6443 --token 369tcl.oe4punpoj9gaijh7(**新的token**) --discovery-token-ca-cert-hash sha256:7ae10591aa593c2c36fb965d58964a84561e9ccd416ffe7432550a0d0b7e4f90(**ca证书sha256编码hash值**) 

Check the node on the master node again and find that the node has joined the cluster.

Guess you like

Origin blog.csdn.net/wangshiqi666/article/details/131365738