Skip to content

Files

Latest commit

author
Anudeep Reddy
Apr 10, 2024
a09a24d · Apr 10, 2024

History

History

cleanup-evicted-pods

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 9, 2021
Mar 19, 2024
Apr 10, 2024

Cleanup evicted pods left behind after disk pressure

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

Workaround

Manual cleanup

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'

Automatic cleanup

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.