Command to delete all pods in all kubernetes namespaces

kubectl delete deployment and pods
kubectl delete namespace
kubectl describe pod
kubectl delete all pods with name
kubectl stop pod
kubectl kill pod
kubectl scale deployment
kubectl jsonpath

Upon looking at the doc there is an api call to delete 'a' pod , is there a way to kill all pods in all namespaces?

There is no command to do exactly what you asked.

Here are some close matches.

You can delete all the pods in a single namespace with this command:

kubectl delete --all pods --namespace=foo

You can delete all namespaces, and every object in every namespace (but not un-namespaced objects, like nodes and some events) with this command:

kubectl delete --all namespaces

However, the latter command is probably not something you want to do, since it will delete things in the kube-system namespace, which will make your cluster not usable.

This command will delete all the namespaces except kube-system, which might be useful:

for each in $(kubectl get ns -o jsonpath="{.items[*]}" | grep -v kube-system);
  kubectl delete ns $each

kubectl Cheat Sheet, What happened: kubectl delete namespace --namespace= --all deletes all The above command should throw an error since --namespace and --all are kubectl delete pods --all deletes all pods in current namespace; the  kubectl --all-in-namespace[=ns] that is specifically a safer alternative to --all, refusing to match any cluster-global resources in same command. Using this doesn't cover the case of specific names given on command line — kubectl delete nodes,pods f00-ba7 can match both a node and a pod that happen to be named f00-ba7. But that's less likely to cause harm in practice

kubectl delete daemonsets,replicasets,services,deployments,pods,rc --all

to get rid of them pesky replication controllers too.

Command to delete all pods in all kubernetes namespaces, #Kubectl get all failed pods. #Store this in "todelete.yaml". generate_file_cmd = "​kubectl get pods --field-selector=status.phase=Failed --all-namespaces  Force Delete StatefulSet Pods This page shows how to delete Pods which are part of a stateful set Manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods. , and explains the considerations to keep in mind when doing so.

You just need sed to do this:

kubectl get pods --no-headers=true --all-namespaces |sed -r 's/(\S+)\s+(\S+).*/kubectl --namespace \1 delete pod \2/e'


  1. use command kubectl get pods --all-namespaces to get the list of all pods in all namespaces.
  2. use --no-headers=true option to hide the headers.
  3. use s command of sed to fetch the first two words, which represent namespace and pod's name respectively, then assemble the delete command using them.
  4. the final delete command is just like: kubectl --namespace kube-system delete pod heapster-eq3yw.
  5. use the e modifier of s command to execute the command assembled above, which will do the actual delete works.

To avoid delete pods in kube-system namespace, just need to add grep -v kube-system to exclude kube-system namespace before the sed command.

`kubectl delete ns -n <namespace> --all` deletes ALL namespaces , --all[=false]: [-all] to select all the specified resources. --cascade[=true]: If true, cascade the deletion of the resources managed by this resource (e.g. Pods created  kubectl delete --all pods --namespace=foo You can delete all namespaces, and every object in every namespace (but not un-namespaced objects, like nodes and some events) with this command: kubectl delete --all namespaces Run kubectl get rs to see that the Deployment updated the Pods by creating a new ReplicaSet and scaling it up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.

Here is a one-liner that can be extended with grep to filter by name.

kubectl get pods -o jsonpath="{.items[*]}" | \
tr " " "\n" | \
xargs -i -P 0 kubectl delete pods {}

A simply script to delete all failed pods from Kubernetes · GitHub, Next, use the kubectl drain command to evict all user pods from the node. They will be scheduled onto other nodes by their controller (  If you want to reach across namespaces, you need to use the fully qualified domain name (FQDN). Not All Objects are in a Namespace. Most Kubernetes resources (e.g. pods, services, replication controllers, and others) are in some namespaces. However namespace resources are not themselves in a namespace.

If you already have pods which are recreated, think to delete all deployments first

kubectl delete -n *NAMESPACE deployment *DEPLOYMENT

Just replace the NAMSPACE and the DEPLOYMENT to corresponding ones, you can get all deployments information by the following command

kubectl get deployments --all-namespaces

Kubernetes - kubectl delete, Get commands with basic output $ kubectl get services # List all services in -n my-ns delete po,svc --all # Delete all pods and services in namespace my-ns  How to force delete a Kubernetes Namespace? Ask Question $ kubectl apply -f tmp.yaml namespace/delete-me configured The command finishes with no error, but the

How to Delete Pods from a Kubernetes Node, xat1gw. Last Updated: July 25, 2019. ·. 8.315K. · isubuzg. Delete all pods in Kubernetes. kubernetes. $ kubectl delete pods --all. Written by isubuzg. Recommend. This page shows how to use kubectl to list all of the Container images for Pods running in a cluster. You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using Minikube , or you can use one of these Kubernetes

Kubectl cheatsheet, What is in a Kubernetes namespace? Delete everything with a single command: jess@Athena:~$ kubectl get pods --all-namespaces apply manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running kubectl apply. This is the recommended way of managing Kubernetes applications on production. See Kubectl Book. Creating Objects. Kubernetes manifests can be defined in YAML or JSON. The file extension .yaml

Delete all pods in Kubernetes (Example), kubectl get all does not list all resources in a namespace. What you expected to happen: As a user performing kubectl get all I expect to see all objects in the current context, including limits. How to reproduce it (as minimally and precisely as possible):

  • ""{.items[*]}" - there are double quotes present in this answer...please check and edit.
  • fixed the quote
  • With the current version of k8s, the command "kubectl delete --all namespaces" does not delete the system stuff anymore... It says e.g.: namespaces "default" is forbidden: this namespace may not be deleted
  • Does this delete the deployment or just the pods?
  • kubectl delete pods --all --all-namespaces seems to work sometimes (not sure what causes it to work in some environments and not in others). It works well from my bastion host but not from laptop. Both running debian and both running the same version of kubectl (cluster version 1.13)
  • This is wrong. This only deletes in the current namespace.
  • Add the -n flag, but sorry that's for one pod at a time and not all at once
  • You are missing ing to also delete ingresses
  • you might want to add "statefulset" as well ( if applicable ). Otherwise it will keep forking new pods even after you run above command!
  • You can also just drop --all-namespaces if you don't want to delete pods in the kube-system namespace
  • What will be the command to delete only few pod? Example: I had spin 20 Pod and now wish to keep just 1.