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