Skip to content

Instantly share code, notes, and snippets.

@shamangeorge
Last active December 30, 2024 17:43
Show Gist options
  • Select an option

  • Save shamangeorge/f5002e1f20e7af7b55bdab2e61189f9f to your computer and use it in GitHub Desktop.

Select an option

Save shamangeorge/f5002e1f20e7af7b55bdab2e61189f9f to your computer and use it in GitHub Desktop.
Delete all evicted kubernetes pods
###
# 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