Created
August 6, 2018 14:41
-
-
Save psxvoid/71492191b7cb06260036c90ab30cc9a0 to your computer and use it in GitHub Desktop.
Delete evicted pods from all namespaces (also ImagePullBackOff and ErrImagePull)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# based on https://gist.github.com/ipedrazas/9c622404fb41f2343a0db85b3821275d | |
# delete all evicted pods from all namespaces | |
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod | |
# delete all containers in ImagePullBackOff state from all namespaces | |
kubectl get pods --all-namespaces | grep 'ImagePullBackOff' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod | |
# delete all containers in ImagePullBackOff or ErrImagePull or Evicted state from all namespaces | |
kubectl get pods --all-namespaces | grep -E 'ImagePullBackOff|ErrImagePull|Evicted' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod |
MathiasVandePol
commented
Sep 15, 2021
•
What about this?
kubectl get pods -A --field-selector=status.phase!=Running --template '{{range .items}}kubectl delete pod -n {{.metadata.namespace}} {{.metadata.name}}{{"\n"}}{{end}}' | sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment