参考清理脚本
#!/bin/bash # used to clear pods with evicted status kubectl get ns | sed '1d' | awk '{print $1}' | while read NS; do # echo "NS=$NS" kubectl get pod -n $NS | grep -i evicted > /dev/null 2>&1 if [ $? -eq 0 ]; then # echo "NS=$NS; ############# " kubectl get pod -n $NS | grep -i evicted | awk '{print $1}' | while read POD do echo "NS=$NS; POD=$POD" kubectl -n $NS delete pod $POD done fi done
然后把它加入到定时任务中执行即可。