Forked from psxvoid/delete-evicted-pods-all-namespaces.sh
Created
August 15, 2018 12:45
-
-
Save svx/a2310feb53fb71ad232bd7f66fada5bc 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 |
do not use kubectl get po --all-namespaces | awk '{if ($4 != "Evicted") system ("kubectl -n " $1 " delete pods " $2 " --grace-period=0 " " --force ")}' this will delete all evited satus pods
kubectl get pods --all-namespaces | grep Evicted | awk '{print "kubectl delete pods -n " $1 " " $2 " --grace-period=0 --force"}' | sh
Show all Failed/Evicted Pods
kubectl get pod --all-namespaces --field-selector=status.phase==Failed
Delete all Failed/Evicted Pods
kubectl delete pod --all-namespaces --field-selector=status.phase==Failed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey this is very wrong