[kubernetes]spec yaml定义command/args

对于DockerFile中的CMD [“”] 以及ENTRYPOINT[“xxx”, “xxxx”]以及kubernetes中的command Args的描述一直很困惑,特别是针对外网下载的image,进行调试验证的时候。需要弄清楚DockerFile与Kubernetes yaml中定义的关系。

其实kubernetes社区已经给出了明确的说明
This table summarizes the field names used by Docker and Kubernetes.

DescriptionDocker field nameKubernetes field name
The command run by the containerEntrypointcommand
The arguments passed to the commandCmdargs

When you override the default Entrypoint and Cmd, these rules apply:

  • If you do not supply command or args for a Container, the defaults defined in the Docker image are used.
  • If you supply a command but no args for a Container, only the supplied command is used. The default EntryPoint and the default Cmd defined in the Docker image are ignored.
  • If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
  • If you supply a command and args, the default Entrypoint and the default Cmd defined in the Docker image are ignored. Your command is run with your args.

Here are some examples:

Image EntrypointImage CmdContainer commandContainer argsCommand run
[/ep-1][foo bar][ep-1 foo bar]
[/ep-1][foo bar][/ep-2][ep-2]
[/ep-1][foo bar][zoo boo][ep-1 zoo boo]
[/ep-1][foo bar][/ep-2][zoo boo][ep-2 zoo boo]

总结如下
进程启动的时候,一般是已Dockerfile中定义的 EntryPoint + CMD, 或者是yaml中定义的command+args的组合
如果kubernetes yaml中定义了command, 以yaml中定义的为准,否则以Dockerfile中定义的Entrypoint为准
如果kubernetes yaml中定义了args, 则以yaml中定义的为准,再之后才是Dockerfile中定义的CMD

demo

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["printenv"]
    args: ["HOSTNAME", "KUBERNETES_PORT"]
  restartPolicy: OnFailure

参考文献
https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值