Tags: kubernetes
To clear all evicted pods from the cluster the following kubectl/jq CLI command can be used:
for n in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}') ; do p="$(kubectl get pods -n $n -o json | jq -r '.items[] | select(.status.reason=="Evicted") | .metadata.name')" if [ -n "${p}" ] ; then echo kubectl delete pods -n $n $p kubectl delete pods -n $n $p fi done