Tuesday, May 8, 2018

Delete all evicted pods in openshift


Delete all evicted pods in openshift


# 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')"


# 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.


ref: https://stackoverflow.com/questions/46419163/what-will-happen-to-evicted-pods-in-kubernetes

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

2 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