首页 > 解决方案 > 我可以在 kubernetes 中运行的任何类似命令为“docker run -ti --rm alpine ls /”

问题描述

在 docker 中,我可以使用选项运行容器,--rm以便在命令完成后容器消失。例如,我可以运行以下命令来列出 Alpine 容器的根目录,并在运行后自行删除:

$ docker run -ti --rm alpine ls /
bin    etc    lib    mnt    proc   run    srv    tmp    var
dev    home   media  opt    root   sbin   sys    usr

如何在中映射类似的命令kubectl

标签: dockerkubernetes

解决方案


以下命令应该这样做:

kubectl run alpinepod --rm -it --image=alpine --restart=Never -- /bin/ls /

“kubectl run”命令类似于“docker container run”,除了它是运行一个 pod 而不是仅仅运行容器。[在 pod 中创建并运行特定图像。] 以下是我们在上述命令中使用的选项的说明(来自 kubectl run --help")

--image='': The image for the container to run. 
--rm=false: If true, delete resources created in this command for attached containers.
-i, --stdin=false: Keep stdin open on the container(s) in the pod, even if nothing is attached.
-t, --tty=false: Allocated a TTY for each container in the pod.
--restart='Always': The restart policy for this Pod.  Legal values [Always, OnFailure, Never].
we have used "Never" so that pod wont go for continuous reboot after the command completion

推荐阅读