kubectl run --command vs -- arguments [英] kubectl run --command vs -- arguments
问题描述
我对下面的命令有点困惑:
I was a little confused with below command:
kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'echo hello;sleep 3600'
YAML:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: busybox
name: busybox
spec:
containers:
- args:
- /bin/sh
- -c
- echo hello;sleep 3600
image: busybox
name: busybox
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}
我知道如果我们不指定参数--command
,那么--
之后的参数将被视为参数.
I know if we don't specify parameter --command
, then parameters after --
will be treated as arguments.
但我想知道,/bin/sh -c "echo hello;sleep 3600"
在有争论的情况下是如何工作的?根据 Kubernetes 文档(https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes),如果我们只在 POD 中指定参数,那么 docker EntryPoint 将用作 EntryPoint 命令.因此,将在 docker 镜像中执行的结果命令将是 Docker EntryPoint + kubectl arguments
.
But I wanted to know, how /bin/sh -c "echo hello;sleep 3600"
was working in case of arguments? According to Kubernetes documentation(https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes), If we specify only arguments in a POD then docker EntryPoint will be used as EntryPoint command. So the resultant command which will be executed in the docker image will be Docker EntryPoint + kubectl arguments
.
由于 Busybox DockerFile 不包含任何 EntryPoint(https://github.com/docker-library/busybox/blob/master/musl/Dockerfile),所以只会使用 kubectl 命令中指定的参数,所以命令看起来像:
As Busybox DockerFile does not contain any EntryPoint(https://github.com/docker-library/busybox/blob/master/musl/Dockerfile), so arguments specified in the kubectl command will only be used, so the command will look like:
/bin/sh -c 'echo hello;sleep 3600'
如果我们指定 --command
,那么根据 Kubernetes 文档,DockerFile 参数(CMD)和命令(EntryPoint)都将被 kubectl 命令中指定的命令覆盖,所以它看起来与上面类似:
And if we specify --command
, then according to Kubernetes documentation, DockerFile arguments(CMD) and command(EntryPoint) both will be overridden with command specified in the kubectl command, so it will look similar to above:
/bin/sh -c 'echo hello;sleep 3600'
所以最后还是一样.
推荐答案
在 Kubernetes 中使用容器时,应注意不要混淆 Kubenetes command
和 Docker Cmd
.
When working with containers in Kubernetes, you should be careful not to mix up Kubenetes command
and Docker Cmd
.
- Kubernetes 中的
command
字段对应于 Docker 中的EntryPoint
字段 - Kubernetes 中的
args
字段对应于 Docker 中的Cmd
字段
- the
command
field in Kubernetes corresponds to theEntryPoint
field in Docker - the
args
field in Kubernetes corresponds to theCmd
field in Docker
来自 Kubernets 文档:
当您覆盖默认的 Entrypoint
和 Cmd
时,这些规则适用:
When you override the default
Entrypoint
andCmd
, these rules apply:
如果您不为容器提供
command
或args
,则默认值使用 Docker 镜像中定义的.
If you do not supply
command
orargs
for a Container, the defaults defined in the Docker image are used.
如果您为容器提供了 command
但没有提供 args
,则只有提供的使用 command
.默认的 EntryPoint
和默认的 Cmd
定义在Docker 镜像将被忽略.
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.
如果你只为容器提供 args
,默认的 Entrypoint
Docker 映像中定义的代码使用您提供的 args
运行.
If you supply only args
for a Container, the default Entrypoint
defined in the Docker image is run with the args
that you supplied.
如果您提供 command
和 args
,默认的 Entrypoint
和Docker 映像中定义的默认 Cmd
将被忽略.你的 command
是使用您的 args
运行.
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
.
这篇关于kubectl run --command vs -- arguments的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!