Kubernetes - delete all pods with a certain status



"How to delete all pods with a status like Error" - that is a question I often get. The DevOps answer is a one-liner, filtering by status.reason and the status we want to query, es example:

kubectl get po -A --all-namespaces -o json | jq '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | "kubectl delete po \(.metadata.name) -n \(.metadata.namespace)"' | xargs -n 1 bash -c

In that case we delete all pods with the Status "Evicted". But it works for every status based filtering. 

Comments

  1. I am stunned by the information that you have on this blog. It shows how well you fathom this subject.
    https://360digitmg.com/course/certification-program-in-iot

    ReplyDelete

Post a Comment

Popular posts from this blog

Deal with corrupted messages in Apache Kafka

Hive query shows ERROR "too many counters"

Embedded Linux won't reboot - how to fix and repair