在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
中映射类似的命令?
应该使用以下命令:
kubectl run alpinepod --rm -it --image=alpine --restart=Never -- /bin/ls /
"kubectl 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