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
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
or another way per-namespace without jq.
ReplyDeletefor evicted in $(oc get pods | grep "Evicted" | awk '{print $1}'); do oc delete pod ${evicted}; done
Thank you!
DeleteI am getting disk pressure issue, how to change eviction policy?
ReplyDelete