Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill pods on Kubernetes local setup

Tags:

kubernetes

I am starting exploring runnign docker containers with Kubernetes. I did the following

  1. Docker run etcd
  2. docker run master
  3. docker run service proxy
  4. kubectl run web --image=nginx

To cleanup the state, I first stopped all the containers and cleared the downloaded images. However I still see pods running.

$ kubectl get pods  NAME                   READY     STATUS    RESTARTS   AGE web-3476088249-w66jr   1/1       Running   0          16m 

How can I remove this?

like image 498
Pankaj Garg Avatar asked Apr 14 '17 11:04

Pankaj Garg


People also ask

How do you kill Kubernetes pods?

Enter the “kubectl delete pod nginx” command in the terminal to delete the pod. Before you execute this command, make sure to confirm the pod's name that you want to destroy. Once you press enter after “kubectl delete pod nginx”, you will see the following output.


2 Answers

To delete the pod:

kubectl delete pods web-3476088249-w66jr 

If this pod is started via some replicaSet or deployment or anything that is creating replicas then find that and delete that first.

kubectl get all 

This will list all the resources that have been created in your k8s cluster. To get information with respect to resources created in your namespace kubectl get all --namespace=<your_namespace>

To get info about the resource that is controlling this pod, you can do

kubectl describe  web-3476088249-w66jr 

There will be a field "Controlled By", or some owner field using which you can identify which resource created it.

like image 135
Sushil Kumar Sah Avatar answered Sep 18 '22 07:09

Sushil Kumar Sah


When you do kubectl run ..., that's a deployment you create, not a pod directly. You can check this with kubectl get deploy. If you want to delete the pod, you need to delete the deployment with kubectl delete deploy DEPLOYMENT.

I would recommend you to create a namespace for testing when doing this kind of things. You just do kubectl create ns test, then you do all your tests in this namespace (by adding -n test). Once you have finished, you just do kubectl delete ns test, and you are done.

like image 33
suren Avatar answered Sep 19 '22 07:09

suren