k8s集群 移除节点操作

注: cn-hangzhou.192.168.34.101 为 我此次需要移除的节点名字

1.确认需要移除的节点上面没有部署我们所需要的资源

$ kubectl get pod -A -o wide |grep -w "cn-hangzhou.192.168.34.101"                               
arms-prom         node-exporter-hdpzn     							192.168.34.101   cn-hangzhou.192.168.34.101   
kube-system       ack-node-problem-detector-daemonset-j4v6s      	192.168.34.101   cn-hangzhou.192.168.34.101   
kube-system       csi-plugin-fw7gl     								192.168.34.101   cn-hangzhou.192.168.34.101 
kube-system       flexvolume-cifs-linux-msxkw      					10.254.23.130    cn-hangzhou.192.168.34.101   
kube-system       kube-flannel-ds-x2q5d          					192.168.34.101   cn-hangzhou.192.168.34.101  
kube-system       kube-proxy-worker-sx5ct          					192.168.34.101   cn-hangzhou.192.168.34.101   
kube-system       logtail-ds-cxwqx             						192.168.34.101   cn-hangzhou.192.168.34.101   

2.设置该节点为不可调度(不分配新的资源到该节点上) (drain命令已经会自动把node设置为不可调度,所以可以省略执行cordon命令)

╭─[10:34:01] yup@YP-7-15 ~
╰─$ kubectl cordon cn-hangzhou.192.168.34.101
node/cn-hangzhou.192.168.34.101 cordoned

3.确认完成后,先排空节点上的pod(每个节点上面都会运行一些系统自带的pod) (daemonset不会被排出节点)

╭─[10:59:46] yup@YP-7-15 ~
╰─$ kubectl drain cn-hangzhou.192.168.34.101 --ignore-daemonsets --force
node/cn-hangzhou.192.168.34.101 already cordoned
WARNING: ignoring DaemonSet-managed Pods: arms-prom/node-exporter-hdpzn, kube-system/ack-node-problem-detector-daemonset-j4v6s, kube-system/csi-plugin-fw7gl, kube-system/flexvolume-cifs-linux-msxkw, kube-system/kube-flannel-ds-x2q5d, kube-system/kube-proxy-worker-sx5ct, kube-system/logtail-ds-cxwqx
node/cn-hangzhou.192.168.34.101 drained

4.排空pod之后,便可以删除节点了

╭─[11:01:40] yup@YP-7-15 ~
╰─$ kubectl delete node cn-hangzhou.192.168.34.101
node "cn-hangzhou.192.168.34.101" deleted
Logo

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

更多推荐