Deleting Pods in a Namespace
Deleting pods in a Kubernetes namespace is a common task when managing your applications. There are several ways to achieve this, depending on your specific requirements.
Deleting a Single Pod
To delete a single pod in a namespace, you can use the following command:
kubectl delete pod pod-name -n namespace-name
Replace pod-name
with the name of the pod you want to delete, and namespace-name
with the name of the namespace.
Deleting Multiple Pods
If you need to delete multiple pods in a namespace, you can use the following command:
kubectl delete pods -n namespace-name --all
This will delete all the pods in the specified namespace.
Deleting Pods Based on Labels
You can also delete pods based on their labels. For example, to delete all pods with the label app=my-app
in the my-namespace
namespace, you can use:
kubectl delete pods -n my-namespace -l app=my-app
Replace app=my-app
with the appropriate label selector for your use case.
Deleting Pods with Confirmation
By default, kubectl delete
will delete the specified resources without prompting for confirmation. If you want to be prompted before deleting the pods, you can use the --dry-run=client
and --force
flags:
kubectl delete pods -n namespace-name --all --dry-run=client --force
This will show you the list of pods that will be deleted, and then prompt you to confirm the action.
Deleting pods in a Kubernetes namespace is a straightforward process, and understanding these various methods will help you effectively manage your Kubernetes applications.