Skip to content

Instantly share code, notes, and snippets.

@cooltoast
Last active January 9, 2020 10:51
Show Gist options
  • Save cooltoast/ed10a63eb96a6a450d164e0f0c6bcebe to your computer and use it in GitHub Desktop.
Save cooltoast/ed10a63eb96a6a450d164e0f0c6bcebe to your computer and use it in GitHub Desktop.
kubectl get pods -a | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
@jconallen
Copy link

I think the -a is needed to allow evicted pods to return, and then the type of object (pod) needs to be added to delete.

kubectl get pods -a | grep Evicted | awk '{print $1}' | xargs kubectl delete pod

@rejith
Copy link

rejith commented Feb 24, 2019

Here is what I use:
kubectl get pods --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -

@cooltoast
Copy link
Author

@jconallen thanks for the comment. I have the -a and pod in my alias locally but forgot to update the gist

@GMartinez-Sisti
Copy link

To delete evicted pods from all the namespaces, I use:

kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs -n 2 -d '\n' bash -c 'kubectl delete pod $0 $1'

This will split the parameters correctly for xargs when using the namespace option..

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