How to kill pods on Kubernetes local setup
Matthew Martinez
I am starting exploring runnign docker containers with Kubernetes. I did the following
- Docker run etcd
- docker run master
- docker run service proxy
- 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 16mHow can I remove this?
33 Answers
To delete the pod:
kubectl delete pods web-3476088249-w66jrIf this pod is started via some replicaSet or deployment or anything that is creating replicas then find that and delete that first.
kubectl get allThis 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-w66jrThere will be a field "Controlled By", or some owner field using which you can identify which resource created it.
3When 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.
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