How to delete pod in Kubernetes

In this post we are going to see how to delete pod in Kubernetes. In Kubernetes, we can delete a specific pod using the kubectl delete command along with the pod’s name. Here’s the general syntax:

kubectl delete pod <pod_name>

Replace <pod_name> with the actual name of the pod you want to delete. For example:

kubectl delete pod mypod

If the pod is part of a specific namespace, you may need to specify the namespace using the -n or --namespace flag:

kubectl delete pod <pod_name> -n <namespace>

For example:

kubectl delete pod mypod -n mynamespace

If you want to delete all pods in a namespace, you can use the following command:

kubectl delete pods --all -n <namespace>

Be careful when deleting pods, as it will result in the termination of the specified pod, and a new one might be automatically created by a replication controller, replica set, or another controller depending on your setup.

If you want to force delete a pod without waiting for it to gracefully terminate, you can use the --grace-period=0 option:

kubectl delete pod <pod_name> --grace-period=0 --force

Keep in mind that using --force may result in data loss or other issues, so use it with caution.

That’s all about How to delete pod in Kubernetes.

You may like.