Kubernetes集群安全地清空一个节点
k8s 集群安全地清空一个节点
清空节点
kubectl drain <node name>
问题
➜ ~ kubectl drain xdf-31-kvm-python-107
node/xdf-31-kvm-python-107 already cordoned
error: unable to drain node "xdf-31-kvm-python-107" due to error:[cannot delete Pods with local storage (use --delete-emptydir-data to override): ailearn-dev/ailearn-composer-interface-v1-f6f756895-wpnx5, ailearn-dev/ailearn-instruction-proxy-svr-v1-666d48bb6d-wlclh, ailearn-dev/kubevpn.traffic.manager, argocd/argocd-dex-server-5665ffc49-j5q2n, kube-system/metrics-server-799d467fd5-7tvc7, cannot delete DaemonSet-managed Pods (use --ignore-daemonsets to ignore): kube-system/calico-node-rcgw7, kube-system/kube-proxy-5rlmq, metallb-system/speaker-rbbvp, monitoring/node-exporter-5sl72], continuing command...
There are pending nodes to be drained:
xdf-31-kvm-python-107
cannot delete Pods with local storage (use --delete-emptydir-data to override): ailearn-dev/ailearn-composer-interface-v1-f6f756895-wpnx5, ailearn-dev/ailearn-instruction-proxy-svr-v1-666d48bb6d-wlclh, ailearn-dev/kubevpn.traffic.manager, argocd/argocd-dex-server-5665ffc49-j5q2n, kube-system/metrics-server-799d467fd5-7tvc7
cannot delete DaemonSet-managed Pods (use --ignore-daemonsets to ignore): kube-system/calico-node-rcgw7, kube-system/kube-proxy-5rlmq, metallb-system/speaker-rbbvp, monitoring/node-exporter-5sl72
如果遇到上术问题,接提示添加下面参数
kubectl drain xdf-31-kvm-python-107 --ignore-daemonsets --delete-emptydir-data
但是又出现下面的问题
➜ ~ k drain xdf-31-kvm-python-107 --ignore-daemonsets --delete-emptydir-data
node/xdf-31-kvm-python-107 already cordoned
error: unable to drain node "xdf-31-kvm-python-107" due to error:cannot delete Pods declare no controller (use --force to override): ailearn-dev/kubevpn.traffic.manager, continuing command...
There are pending nodes to be drained:
xdf-31-kvm-python-107
cannot delete Pods declare no controller (use --force to override): ailearn-dev/kubevpn.traffic.manager
按提示添加--force
参数
kubectl drain xdf-31-kvm-python-107 --ignore-daemonsets --delete-emptydir-data --force
参数说明:
- –ignore-daemonsets: 忽略deamonset控制器的pod,如果不忽略,deamonset控制器控制的pod被删除后可能马上又在此节点上启动起来,会成为死循环
- –delete-emptydir-data: 即使pod使用了emptyDir也删除,emptyDir也会删除
- –force: 不加force参数只会删除该NODE上由ReplicationController, ReplicaSet, DaemonSet,StatefulSet或者Job创建的Pod,加了后还会删除’裸奔的pod’(没有绑定到任何replication controller)