极客时间返利平台,你可以在上边通过山月的链接购买课程,并添加我的微信 (shanyue94) 领取返现。
每天晚上九点 B站讲解前端工程化直播,并解答相关问题。

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

Issue

欢迎在 Gtihub Issue 中回答此问题: Issue 355 (opens new window)

$ 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 (opens new window)

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

更加精确。

Last Updated: 11/27/2021, 10:11:48 AM