DEV Community

Dean
Dean

Posted on • Originally published at veducate.co.uk on

Quick Tip – Kubernetes – Delete all evicted pods across all namespaces

I’m currently troubleshooting an issue with my Kubernetes clusters where pods keep getting evicted, and this is happening across namespaces as well.

The issue now that I am faced with, is being able to keep ontop of the issues. When I run:

kubectl get pods -A | grep Evicted
Enter fullscreen mode Exit fullscreen mode

I’m presented with 100’s of returned results.

kubectl get pods -A grep Evicted

So to quickly clean this up, I can run the following command:

kubectl get pods -A | grep Evicted | awk '{print $1,$2,$4}' | xargs kubectl delete pod $2 -n $1
Enter fullscreen mode Exit fullscreen mode

Breaking down the command:

  • Get all pods across all namespaces
  • Filter by term “Evicted”
  • Manipulate the output by selecting the data in field 1, 2 and 4
  • Use xargs to read from the standard output to place the data from the previous pipe into the “kubectl” command.

This command will cycle and remove everything you need. You can use this command line for other status of pods if needed.

kubectl get pods -A grep Evicted awk xargs kubectl delete pod

Now I need to get back to troubleshooting my cluster issues.

Regards

Follow @Saintdle

Dean Lewis

The post Quick Tip – Kubernetes – Delete all evicted pods across all namespaces appeared first on vEducate.co.uk.

Discussion (0)