【问题标题】:How to delete the pod for one time task in kubernetes automatically?如何在 Kubernetes 中自动删除一次性任务的 pod?
【发布时间】:2017-12-29 17:23:39
【问题描述】:

为了检查状态,我使用交互式 shell 在 kubernetes 中启动了busybox

$ 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

当我退出 shell 时,我希望 pod 也会被删除。虽然它以完成状态存在。

$ kubectl get pods -a
NAME                     READY     STATUS      RESTARTS   AGE
busybox                  0/1       Completed   0          58m

我必须删除 pod,这很烦人。

我们是否有简单的参数可以用来让 k8s 删除这个任务作业的 pod?

【问题讨论】:

    标签: kubernetes busybox minikube


    【解决方案1】:

    只需添加--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:如果为真,则删除在此命令中为附加容器创建的资源。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-16
    • 2019-07-31
    • 1970-01-01
    • 2021-09-21
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多