docker - 我可以在 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
?
解决方案
以下命令应该这样做:
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
推荐阅读
- c - 获取用户输入并将其分割成一个结构以传回给 execvp
- python - 如何处理包含多个数据的 JSON
- javascript - 如何检查元素是否包含javascript中的类
- php - Phalcon PHP 中的会话持久性问题
- java - Java计划任务在后台重复运行
- reactjs - 将文件上传状态从 react-dropzone 组件发送到父级?
- django - 使用 FactoryBoy 自动添加
- encryption - Azure 资源管理器 REST API - 静态加密?
- r - 在 R 中创建自定义距离矩阵函数
- java - java.lang.NoClassDefFoundError: kotlin/TypeCastException 使用 OkHttp 运行代码时