循环遍历清理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
*************** 当你发现自己的才华撑不起野心时,就请安静下来学习吧!***************
原文地址:https://www.cnblogs.com/lvzhenjiang/p/15428454.html