serverk8s【Q352】k8s 中如何删除所有 Evicted 状态的 pod

k8s 中如何删除所有 Evicted 状态的 pod

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 355

Author 回答者: shfshanyue

$ kubectl get pods
NAME                                             READY   STATUS             RESTARTS   AGE
cert-manager-5d8fd69d88-4nxw5                    1/1     Running            0          63d
cert-manager-5d8fd69d88-f7f2w                    0/1     Evicted            0          63d
cert-manager-5d8fd69d88-mpgqq                    0/1     Evicted            0          63d
cert-manager-5d8fd69d88-s7dtg                    0/1     Evicted            0          232d
cert-manager-5d8fd69d88-vdmrx                    0/1     Evicted            0          63d
cert-manager-5d8fd69d88-zlpv4                    0/1     Evicted            0          63d
cert-manager-cainjector-755bbf9c6b-455nm         0/1     Evicted            0          63d

可通过 kubectl get pods 来找到 Evicted 状态的 POD,通过 awkkubectl delete pod 选中目标 pod 并删除,命令如下

$  kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod

Author 回答者: wi1dcard

kubectl delete po --field-selector status.phase=Evicted

更加精确。