k8s批量删除Evicted Pods

后端开发 解决问题Linux
Zyao89 2020年5月8日星期五 12:09

# 背景

查询pod状态

kubectl -n kube-system get pods | grep coredns | grep Evicted
1

查询结果为:

coredns-67cb7b5f46-2crxg                0/1     Evicted   0          4h56m
coredns-67cb7b5f46-2ds7n                0/1     Evicted   0          4h56m
coredns-67cb7b5f46-2pzw5                0/1     Evicted   0          4h56m
coredns-67cb7b5f46-4f8nm                0/1     Evicted   0          166m
coredns-67cb7b5f46-4gncz                0/1     Evicted   0          10h
coredns-67cb7b5f46-4lnw2                0/1     Evicted   0          166m
coredns-67cb7b5f46-4smp6                0/1     Evicted   0          166m
coredns-67cb7b5f46-5hx49                0/1     Evicted   0          166m
coredns-67cb7b5f46-6jxqn                0/1     Evicted   0          166m
coredns-67cb7b5f46-6qh9z                0/1     Evicted   0          166m
coredns-67cb7b5f46-6rn4c                0/1     Evicted   0          10h
coredns-67cb7b5f46-7jsth                0/1     Evicted   0          10h
coredns-67cb7b5f46-7mzvb                0/1     Evicted   0          166m
coredns-67cb7b5f46-92t2k                0/1     Evicted   0          4h56m
coredns-67cb7b5f46-9jqdm                0/1     Evicted   0          10h
coredns-67cb7b5f46-9rxsc                0/1     Evicted   0          4h56m
coredns-67cb7b5f46-9xmkk                0/1     Evicted   0          166m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

发现有很多 Evicted 状态的pod

问题原因:这是由于node节点的磁盘或内存资源不够后将现有的pod进行了驱赶。

# 解决

批量删除所有 Evicted 状态的pod即可

kubectl -n kube-system  get pods | grep coredns | grep Evicted | awk '{print$1}'| xargs kubectl -n kube-system delete pods
1

可自定义替换 namespacepodName

kubectl -n ${namespace}  get pods | grep ${podName} | grep Evicted | awk '{print$1}'| xargs kubectl -n ${namespace} delete pods
1
#指定pod所在的命名空间
kubectl -n kube-system get pods | grep coredns
1
2

执行完成后,成功删除全部 Evicted 状态的Pods

作者: Zyao89; 转载请保留
版权声明: 自由转载-非商用-非衍生-保持署名
上次编辑时间: 2020年8月7日星期五 16:07