Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force delete kubernetes pods?

Tags:

kubernetes

I have the following pods:

NAME                                                 READY     STATUS        RESTARTS   AGE xxx-myactivities-79f49cdfb4-nwg22                      1/1       Terminating   0          10h xxx-mysearch-55864b5c59-6bnwl                          1/1       Terminating   0          1d xxx-mysearch-55864b5c59-rpn48                          1/1       Terminating   0          13h xxx-mysearch-6ff9bbb7cb-9qgbb                          1/1       Terminating   0          3d 

I am running the following code to forcefully delete those pods:

# # Clean up dying pods # pods=$( kubectl get pods | grep -v Running | tail -n +2 | awk -F " " '{print $1}' ) for pod in $pods; do     kubectl delete pod $pod --force done 

Here is the output:

pod "xxx-myactivities-79f49cdfb4-nwg22" deleted pod "xxx-mysearch-55864b5c59-6bnwl" deleted pod "xxx-mysearch-55864b5c59-rpn48" deleted pod "xxx-mysearch-6ff9bbb7cb-9qgbb" deleted 

After cleaning up, those pods still hang around.

NAME                                                 READY     STATUS        RESTARTS   AGE xxx-myactivities-79f49cdfb4-nwg22                      1/1       Terminating   0          10h xxx-mysearch-55864b5c59-6bnwl                          1/1       Terminating   0          1d xxx-mysearch-55864b5c59-rpn48                          1/1       Terminating   0          13h xxx-mysearch-6ff9bbb7cb-9qgbb                          1/1       Terminating   0          3d 

How do I clean up those pods?

like image 671
user9524761 Avatar asked May 14 '18 18:05

user9524761


People also ask

How do I delete failed pods in Kubernetes?

For deleting all failed pods in all namespaces you can use this command: kubectl delete pods --field-selector status. phase=Failed -A . But, for using this command, you need to configure the restartPolicy as the pod will restart again and again. And that is it!

How do you clean up Kubernetes pods?

If you create pods directly (not via a deployment), you can delete them directly, and they will stay deleted. Pods (that were created directly), deployments, and services can all be deleted independently of one another, order doesn't matter. If you want to delete them but not the namespace, delete them in any order.


1 Answers

To clean the pods you need to delete their deployments namespace.

First discover that deployments existed:

$ kubectl get deployments --all-namespaces NAME                               READY     STATUS        RESTARTS   AGE chetabahana-web-584b95d576-62ccj   1/1       Running       0          20m tutorial-web-56fbccc56b-wbwjq      1/1       Running       0          1m 

Delete the deployment <NAME>-xxxx like this:

$ kubectl delete deployment <NAME> 

For example to delete tutorial-web-56fbccc56b-wbwjq run:

$ kubectl delete deployment tutorial 

Then all corresponded pods of tutorial-xxxx will terminate by itself.

NAME                               READY     STATUS        RESTARTS   AGE chetabahana-web-584b95d576-62ccj   1/1       Running       0          20m tutorial-web-56fbccc56b-wbwjq      0/1       Terminating   0          1m 
like image 170
Chetabahana Avatar answered Sep 17 '22 16:09

Chetabahana