Skip to content

Instantly share code, notes, and snippets.

@clarkmcc
Last active May 11, 2022 12:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkmcc/874af0371fbc644a5ba80d609d25a32b to your computer and use it in GitHub Desktop.
Save clarkmcc/874af0371fbc644a5ba80d609d25a32b to your computer and use it in GitHub Desktop.
Deletes Kubernetes pods with a status of Shutdown that are usually left over after a GKE pre-emptible node goes offline.
#!/bin/sh
for namespace in $(kubectl get ns | awk '{print $1}' | grep -v NAME); do
for pod in $(kubectl get pod -n $namespace --field-selector=status.phase!=Running | grep Shutdown | awk '{print $1}' | grep -v NAME); do
kubectl delete pod -n "$namespace" "$pod"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment