When a node starts to evict pods under disk pressure, the evicted pods are left behind. All the resources like volumes, IP, containers, etc will be cleaned up and delete. But the pod object will be left behind in "evicted" status. Per upstream this is intentional
NOTE: This script is designed to work on Linux machines.
kubectl get pods --all-namespaces -ojson | jq -r '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | .metadata.name + " " + .metadata.namespace' | xargs -n2 -l bash -c 'kubectl delete pods $0 --namespace=$1'
This is a cronjob that runs every 30 mins inside the cluster that will find and remove any pods with the status of "Evicted."
kubectl apply -f deploy.yaml
NOTE: This YAML uses the image rancherlabs/swiss-army-knife
.