Last active
December 30, 2024 17:43
-
-
Save shamangeorge/f5002e1f20e7af7b55bdab2e61189f9f to your computer and use it in GitHub Desktop.
Delete all evicted kubernetes pods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### | |
| # Delete all Evicted pods (in all namespaces) | |
| # Taken from https://gist.github.com/ipedrazas/9c622404fb41f2343a0db85b3821275d?permalink_comment_id=3216637#gistcomment-3216637 | |
| ### | |
| # Target the cluster you want | |
| export KUBECONFIG=/path/to/your/kubeconfig/file | |
| # Dry run | |
| kubectl get po -A --all-namespaces -o json | jq '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | "kubectl delete po \(.metadata.name) -n \(.metadata.namespace)"' | |
| # Run it | |
| kubectl get po -A --all-namespaces -o json | jq '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | "kubectl delete po \(.metadata.name) -n \(.metadata.namespace)"' | xargs -n 1 bash -c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment