diff --git a/README.md b/README.md index c4227bf..dc155ca 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Kubernetes is an open‑source platform that automates the deployment, scaling, - [Create an pod](#create-an-pod) - [Get Pod](#get-pod) - [delete Pod](#delete-pod) + - [delete all Failed pods](#delete-all-failed-pods) - [delete all pods with prefix](#delete-all-pods-with-prefix) - [OOMKilled](#oomkilled) - [Attach to an pod](#attach-to-an-pod) @@ -250,6 +251,30 @@ echo $POD_NAME kubectl delete pod -n appNamespace -l app=myAppName ``` +### delete all Failed pods + + +``` bash +kubectl get pods --all-namespaces --field-selector=status.phase=Failed --no-headers | wc -l +``` + +``` bash +count=0 +while true; do + pods=$(kubectl get pods --all-namespaces --field-selector=status.phase=Failed \ + -o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' \ + | head -n 100) + + [ -z "$pods" ] && break + + echo "Batch $((++count)): deleting up to 100 pods" + + while read ns name; do + kubectl delete pod "$name" -n "$ns" + done <<< "$pods" +done +``` + ### delete all pods with prefix ``` bash