Myluzh Blog

K8S 批量删除被驱逐的Pod(Evicted Pods)

发布时间: 2024-4-7 文章作者: myluzh 分类名称: Kubernetes 朗读文章


0x01 故障
集群中一个deployment中有很多Evicted的pod
root@iZbp12bkuvg20e1j3y9gtxZ:~# kubectl get pod -n base-ops
NAME                        READY   STATUS    RESTARTS   AGE
registry-6d7b7c9fb4-22f2x   0/1     Evicted   0          10d
registry-6d7b7c9fb4-24r7j   0/1     Evicted   0          10d
registry-6d7b7c9fb4-25clg   0/1     Evicted   0          10d
...

0x02 原因

原因:由于node节点的磁盘或内存资源不够后将现有的pod进行了驱赶。可以把磁盘资源释放后,批量删除Evicted Pod
kubectl -n base-ops  get pods | grep Evicted | awk '{print$1}' |xargs kubectl -n base-ops delete pods

0x03 解决方案
批量删除所有“Evicted”状态的pod即可
root@iZbp12bkuvg20e1j3y9gtxZ:~# kubectl -n base-ops  get pods | grep Evicted |awk '{print$1}'|xargs kubectl -n base-ops delete pods
pod "registry-6d7b7c9fb4-22f2x" deleted
pod "registry-6d7b7c9fb4-24r7j" deleted
pod "registry-6d7b7c9fb4-25clg" deleted

标签: k8s pod evicted 驱逐

发表评论