Kubectl: Delete All Pods in Namespace

Pods in Kubernetes (K8s) can be deleted by using a simple kubectl delete pod command.

If there are multiple Pods in a namespace and you want to delete them all, this also can be done using the appropriate kubectl command.

This short post shows how to delete all Pods in a specific namespace using the kubectl command.

Cool Tip: A wildcard deletion of Pods using a kubectl command! Read more →

Delete All Pods in Namespace using Kubectl

To delete all Pods in a namespace using the kubectl command, execute:

$ kubectl delete --all pods -n <namespaceName>

Replace <namespaceName> with the namespace name in which you want to delete all Pods.

ℹ️ Note, that if a Pod is controlled by a Deployment, StatefulSet, or whatever, instead of being deleted it will be actually 🔁 restarted and recreated.

To delete the Pod without getting it restarted and recreated, delete the resource that it is controlled by, for example:

$ kubectl delete deployment.apps/<deploymentName> -n <namespaceName>
- or -
$ kubectl delete statesfulset.apps/ <statefulSettName> -n <namespaceName>

To list all the resources in a namespace, execute:

$ kubectl get all -n <namespaceName>

The resource that controls the Pod can also be identified as follows:

$ kubectl describe pod <podName> -n <namespaceName> | grep -i "Controlled By"

Cool Tip: Forcefully delete K8s resources (Pods, Deployments, Services, etc.) stuck in a “Terminating” or “Unknown” state using kubectl! Read more →

Was it useful? Share this post with the world!

Leave a Reply