循环遍历清理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
上一篇:1069 The Black Hole of Numbers (20 分)【难度: 简单 / 知识点: 模拟】


下一篇:Windows系统cmd命令检测dll文件