1. 查看集群的节点

[root@k8s-master ~]# kubectl get nodes
NAME         STATUS   ROLES                  AGE   VERSION
k8s-master   Ready    control-plane,master   66m   v1.23.8
k8s-node1    Ready    <none>                 61m   v1.23.8
k8s-node2    Ready    <none>                 61m   v1.23.8
[root@k8s-master ~]# 

2. 删除node2节点

2.1 驱逐node2节点上的pod

#k8s-node2是node2的hostname
[root@k8s-master ~]# kubectl drain k8s-node2 --delete-local-data --force --ignore-daemonsets
Flag --delete-local-data has been deprecated, This option is deprecated and will be deleted. Use --delete-emptydir-data.
node/k8s-node2 cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/calico-node-bcgz5, kube-system/kube-proxy-x7c25
evicting pod kube-system/calico-kube-controllers-677cd97c8d-dxwxl
evicting pod default/nginx-85b98978db-bhn8r
pod/calico-kube-controllers-677cd97c8d-dxwxl evicted
pod/nginx-85b98978db-bhn8r evicted
node/k8s-node2 drained
[root@k8s-master ~]# 

2.2 删除这个node2节点

[root@k8s-master ~]# kubectl delete nodes k8s-node2  
node "k8s-node2" deleted
[root@k8s-master ~]# 

2.3 验证是否删除成功

[root@k8s-master ~]# kubectl get nodes
NAME         STATUS   ROLES                  AGE   VERSION
k8s-master   Ready    control-plane,master   70m   v1.23.8
k8s-node1    Ready    <none>                 65m   v1.23.8
[root@k8s-master ~]# 

3. 删除node2节点的相关文件(必须!否则会影响改机器以后加入新集群)

kubeadm reset
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
systemctl start docker
systemctl start kubelet
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐