Skip to content

Instantly share code, notes, and snippets.

@nataz77
Last active April 22, 2020 12:38
Show Gist options
  • Save nataz77/52696afd38e8e0fe5f68a3e532e43153 to your computer and use it in GitHub Desktop.
Save nataz77/52696afd38e8e0fe5f68a3e532e43153 to your computer and use it in GitHub Desktop.
Script to delete all failed/evicted pods from a Kubernetes cluster
#!/bin/bash
#Usage: ./kubecleanup {namespace}
if [ -z $1 ]
then
echo 'No namespace selected, proceeding on default'
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
else
kubectl get pods -n $1 | grep Evicted | awk '{print $1}' | xargs kubectl delete pod -n $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment