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
文章来源地址https://www.toymoban.com/news/detail-578828.html
文章来源:https://www.toymoban.com/news/detail-578828.html
到了这里,关于k8s删除node节点的方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!