39
votes

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?

3
This is already answered here!Pankaj Garg

3 Answers

54
votes

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.

12
votes

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.

3
votes

If you defined your object as Pod then

kubectl delete pod <--all | pod name> 

will remove all of the generated Pod. But, If wrapped your Pod to Deployment object then running the command above only will trigger a re-creation of them.

In that case, you need to run

kubectl delete deployment <--all | deployment name> 

That will also remove the Service object that is related to the deleted Deployment