步骤1:驱逐节点

[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
localhost.localdomain Ready <none> 5m35s v1.23.9
master Ready control-plane,master 41m v1.23.9
work01 Ready <none> 5m44s v1.23.9
work03 Ready <none> 5m33s v1.23.9
[root@master ~]# kubectl cordon localhost.localdomain
node/localhost.localdomain cordoned

步骤2:设置节点为不可调度

[root@master ~]# kubectl  drain localhost.localdomain --ignore-daemonsets
node/localhost.localdomain already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/calico-node-rhk9d, kube-system/kube-proxy-72g66
node/localhost.localdomain drained

步骤3:删除该节点

[root@master ~]# kubectl delete node localhost.localdomain
node "localhost.localdomain"

步骤4:若需要重新部署该节点
在该节点上执行kubeadm reset

[root@work02 ~]# kubeadm reset
[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W0803 20:09:56.890959 34149 removeetcdmember.go:80] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] No etcd config found. Assuming external etcd
[reset] Please, manually reset etcd to prevent further issues
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
[reset] Deleting contents of stateful directories: [/var/lib/kubelet /var/lib/dockershim /var/run/kubernetes /var/lib/cni]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.