本文永久链接: https://www.xtplayer.cn/kubernetes/kubectl-delete-evicted-pods/

#!/bin/bash

kubectl get pods --all-namespaces -o go-template='{{range .items}} {{if (or (eq .status.phase "Evicted") (eq .status.phase "Failed" ))}} {{.metadata.name}}{{" "}} {{.metadata.namespace}} {{"\n"}}{{end}} {{end}}' | while read epod namespace; do kubectl -n $namespace delete pod $epod; done;