循环遍历清理Kubernetes中异常的pod

循环遍历清理异常的pod

#!/bin/bash
namespace=`kubectl get ns -o jsonpath="{.items[*].metadata.name}"`
pod_status=("Evicted" "ImagePullBackOff"  "ContainerCreating" "ErrImagePull" "ContainerCreating" "Pending" "Completed" "CrashLoopBackOff" "Init:ImagePullBackOff" "Init:CrashLoopBackOff")

for istatus in ${pod_status[@]};
do
  for iname in ${namespace[@]};
  do
    echo "Get un-healthy pod:" $iname : $istatus
    for each in $(kubectl get pods -n $iname|grep $istatus|awk '{print $1}');
    do
      kubectl delete pods $each -n $iname
    done
  done
done
posted @ 2021-10-20 13:12  吕振江  阅读(182)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end