From 4e914398fd943832ab38854433e63af3b92da2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Fernandes?= Date: Sun, 13 Sep 2026 19:26:17 +0000 Subject: [PATCH] modified: README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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