In order to check status, I started the busybox
in kubernetes using interactive shell.
$ kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
/ # exit
$ kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
Error from server (AlreadyExists): pods "busybox" already exists
When I exit from the shell, I expect the pod will be deleted as well. While it exists there in completed status.
$ kubectl get pods -a
NAME READY STATUS RESTARTS AGE
busybox 0/1 Completed 0 58m
I have to delete the pod, it is annoying.
DO we have simple parameter I can use to ask k8s to delete the pod for this one task job ?
Destroy Pod The action of deleting the pod is simple. To delete the pod you have created, just run kubectl delete pod nginx . Be sure to confirm the name of the pod you want to delete before pressing Enter. If you have completed the task of deleting the pod successfully, pod nginx deleted will appear in the terminal.
If you create pods directly (not via a deployment), you can delete them directly, and they will stay deleted. Pods (that were created directly), deployments, and services can all be deleted independently of one another, order doesn't matter. If you want to delete them but not the namespace, delete them in any order.
Simply run “kubectl delete pod Nginx” to remove the pod you have made. The pod will be deleted as you can see in the below image upon the execution of the following command in the shell. If you have successfully destroyed the pod, the command “pod Nginx deleted” will be shown in the console.
If you manually deploy a single pod and then delete it, your service will go down and won't come back up. If a service is running through a replica set but with only one pod, the service will become unavailable after deleting the pod.
Just add --rm
:
$ kubectl run busybox -i --tty --image=busybox --restart=Never --rm -- sh
If you don't see a command prompt, try pressing enter.
/ # exit
$ kubectl get pod busybox
Error from server (NotFound): pods "busybox" not found
--rm=false
: If true, delete resources created in this command for attached containers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With