[kubernetes]specyaml定义command/args
其实kubernetes社区已经给出了明确的说明
This table summarizes the field names used by Docker and Kubernetes.
Description Docker field name Kubernetes field name
The command run by the container Entrypoint command
The arguments passed to the command Cmd args
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 Entrypoint Image Cmd Container command Container args Command 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/
以上是 [kubernetes]specyaml定义command/args 的全部内容, 来源链接: utcz.com/z/514984.html