Tuesday, May 8, 2018

Delete all evicted pods in openshift


Delete all evicted pods in openshift:

Please check the commands thoroughly before executing it.

# This is for the current namespace
# eval "$(oc get pods -o json | jq -r '.items[] | select(.status.phase == "Failed" and .status.reason == "Evicted") | "oc delete pod --namespace " + .metadata.namespace + " " + .metadata.name')"


# This is for all namespaces
# eval "$(oc get pods -o json --all-namespaces | jq -r '.items[] | select(.status.phase == "Failed" and .status.reason == "Evicted") | "oc delete pod --namespace " + .metadata.namespace + " " + .metadata.name')"


Here,  jq - commandline JSON processor
You need to install jq first.


PS: Thanks to Stackoverflow!

Another PS:
As per the reader's comment :
Another way per-namespace without jq.

# for evicted in $(oc get pods | grep "Evicted" | awk '{print $1}'); do oc delete pod ${evicted}; done



3 comments:

  1. or another way per-namespace without jq.


    for evicted in $(oc get pods | grep "Evicted" | awk '{print $1}'); do oc delete pod ${evicted}; done

    ReplyDelete
  2. I am getting disk pressure issue, how to change eviction policy?

    ReplyDelete