简体   繁体   中英

How to delete the pod for one time task in kubernetes automatically?

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM