Friday, July 3, 2026

[DevOps] K8s: How to delete all pods that are not Running



Sometimes you need to delete all pods in a cluster using the kubectl utility.

This script will delete all pods that are not in the Running state — such as Terminating and Pending pods.
bash
kubectl get pods -A | grep -E "Terminating|Pending" | awk '{print $1, $2}' | while read ns pod; do kubectl delete pod $pod -n $ns --force --grace-period=0; done