其他分享
首页 > 其他分享> > 循环遍历清理Kubernetes中异常的pod

循环遍历清理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

标签:kubectl,遍历,iname,Kubernetes,do,done,istatus,pod
来源: https://www.cnblogs.com/lvzhenjiang/p/15428454.html