Skip to content

Instantly share code, notes, and snippets.

@zparnold
Last active January 13, 2025 17:40
Show Gist options
  • Save zparnold/0e72d7d3563da2704b900e3b953a8229 to your computer and use it in GitHub Desktop.
Save zparnold/0e72d7d3563da2704b900e3b953a8229 to your computer and use it in GitHub Desktop.
A simply script to delete all failed pods from Kubernetes
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
@jeremych1000
Copy link

kubectl delete pods --field-selector status.phase=Failed --all-namespaces
kubectl delete pods --field-selector status.phase=Error --all-namespaces
kubectl delete pods --field-selector status.phase=Succeeded --all-namespaces

#ALL
kubectl delete pods --field-selector status.phase!=Running --all-namespaces

thank you so much - this is the cleanest by far

@arushdesp
Copy link

The simplest solution possible would be like

NAMESPACE="test"

kubectl delete pods -n $NAMESPACE --field-selector=status.phase!=Running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment