Skip to content

1.查看集群状态

bash
[root@kube-master-01 ~]# kubectl get node
NAME             STATUS   ROLES    AGE   VERSION
kube-master-01   Ready    <none>   23d   v1.29.7
kube-node-01     Ready    <none>   23d   v1.29.7
kube-node-02     Ready    <none>   23d   v1.29.7
[root@kube-master-01 ~]# kubectl get node
NAME             STATUS   ROLES    AGE   VERSION
kube-master-01   Ready    <none>   23d   v1.29.7
kube-node-01     Ready    <none>   23d   v1.29.7
kube-node-02     Ready    <none>   23d   v1.29.7

1.1 禁止调度

bash
[root@kube-master-01 ~]# kubectl cordon kube-node-02
node/kube-node-02 cordoned

[root@kube-master-01 ~]# kubectl get node
NAME             STATUS                     ROLES    AGE   VERSION
kube-master-01   Ready                      <none>   23d   v1.29.7
kube-node-01     Ready                      <none>   23d   v1.29.7
kube-node-02     Ready,SchedulingDisabled   <none>   23d   v1.29.7
[root@kube-master-01 ~]# kubectl cordon kube-node-02
node/kube-node-02 cordoned

[root@kube-master-01 ~]# kubectl get node
NAME             STATUS                     ROLES    AGE   VERSION
kube-master-01   Ready                      <none>   23d   v1.29.7
kube-node-01     Ready                      <none>   23d   v1.29.7
kube-node-02     Ready,SchedulingDisabled   <none>   23d   v1.29.7

1.2 驱逐Pod

bash
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

❌ 注意

kubectl drain --ignore-daemonsets --delete-local-data

低版本使用(1.24之前) --delete-local-data

1.3 停止服务

$ systemctl stop kubelet kube-proxy
$ systemctl stop kubelet kube-proxy

1.4 删除节点

bash
kubectl delete node <node-name>
kubectl delete node <node-name>

1.5 删除数据目录

cat kubelet.conf
cat kubelet.conf

确认是否有 root-dir 参数。如果有的话,那kubelet数据就存放在该目录下,默认在 /var/lib/kubelet 目录下

docker

cat /etc/docker/daemon.json
cat /etc/docker/daemon.json

确认是否有 data-root 或者 graph 参数。如果有的话,那docker数据就存放在该目录下,默认在 /var/lib/docker 目录下

  • 清理docker数据
docker system prune -af
docker system prune -af
  • 停止docker服务
bash
 systemctl stop docker
 systemctl stop docker
  • 取消挂载
bash
$ umount $(df -HT | grep '/var/lib/kubelet/pods' | awk '{print $7}')
$ rm -rf /var/lib/kubelet/ /data/docker/data/
$ umount $(df -HT | grep '/var/lib/kubelet/pods' | awk '{print $7}')
$ rm -rf /var/lib/kubelet/ /data/docker/data/

containerd

1.6 删除k8s网络插件目录

$ rm -rf /opt/cni/bin /etc/cni/net.d /var/lib/cni
$ rm -rf /opt/cni/bin /etc/cni/net.d /var/lib/cni
  • 删除启动文件
bash
#根据各自的路径进行删除
$ rm -rf /usr/lib/systemd/system/kubelet.service /usr/lib/systemd/system/kube-proxy.service
#根据各自的路径进行删除
$ rm -rf /usr/lib/systemd/system/kubelet.service /usr/lib/systemd/system/kube-proxy.service