jack miao
jack miao

Reputation: 1498

cant delete pod using kubctl delete pod <pod>

I want to delete a pod permanently so I can create the deployment.yaml and derveice.yaml again from fresh, so I tried:

 kubctl delete pod <pod>

and the pod is still there, also tried:

kubectl delete pods <pod> --grace-period=0

and didnt work.

the only thing that worked is when I set the deployment replicas: 0 and then apply it, but the when i try to create new deployment i get:

Error from server: error when creating "myService/deployment.yaml": deployments.extensions "myService" already exists

Upvotes: 9

Views: 17890

Answers (4)

Pawan Kumar
Pawan Kumar

Reputation: 890

Pods are created by Deployment, so when you delete a Pod then Deployment automatically create it base on replicas value, you have to delete Deployment and then create it again,

You can use:

kubectl create -f deployment.yml
kubectl delete -f deployment.yml

Upvotes: 15

Prashanth Sams
Prashanth Sams

Reputation: 21169

Deleting Deployment specific to the pods will terminate the pods automatically

kubectl get deployments

kubectl delete deployment deployment_name_to_delete --namespace=default  
(e.g., kubectl delete deployment ngnix --namespace=default)

Upvotes: 8

jamlee
jamlee

Reputation: 1353

kubectl delete --grace-period=0  --force --namespace=system pod mysql-84fbb8bfc6-lhlnh

Upvotes: 0

Suhas Chikkanna
Suhas Chikkanna

Reputation: 1520

1).Note that every pod is generated based on its deployment file. Hence, every time you delete a pod, it comes up again because you defined the value 'replicas: 1' in the deployment file. And in such a case using the command 'kubectl delete pods --grace-period=0', too will not work since the pod will be again generated based on the deployment file.

2). The reason why you get the error you mentioned in the question is because the deployment still exists, all you did was setting 'replicas: 0' which made the no. of pods that should come up or run on the cluster, equal to zero.

3).To delete a Pod/s permanently, You will have to first delete the deployment file of that pod and then delete the pod(optional). This will delete the pod permanently. And of course, the deployment itself will be deleted permanently. The command to do that is :- kubectl delete -f deployment_file_name.yml And sure you can alternatively, delete the deployment file from Kubernetes's UI as well.

Upvotes: 1

Related Questions