k8s删除node节点的方法

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

你可能感兴趣的:(kubernetes,kubernetes,容器,云原生)