[k8s] command和args
k8s中的command和args可以覆盖docker镜像中的entrypoint和cmd。其中,k8s-command可以覆盖docker-entrypoint,k8s-args可以覆盖docker-cmd。在k8s pod yaml中,对于command和args字段缩进与不缩进的区别:不缩进加不加引号都行;中不用缩进(有短横线的地方表示这是数组中的一个元素,短横线不需要缩进。注意上面comm
k8s中的command和args可以覆盖docker镜像中的Entrypoint和Cmd。其中,k8s的command可以覆盖docker镜像中的Entrypoint,k8s的args可以覆盖docker镜像中的Cmd。参考 Difference between Docker ENTRYPOINT and Kubernetes container spec COMMAND?
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.
了解一下entrypoint的意义:ENTRYPOINT 入口点
很多官方镜像多会使用entrypoint,看看redis:https://github.com/docker-library/redis/blob/master/Dockerfile.template#L116C2-L117C36
===============================================
关于pod yaml中的数组缩进,k8s的官方pod yaml中不用缩进(有短横线的地方表示这是数组中的一个元素,短横线不需要缩进。):
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx // 这里没有缩进
image: nginx:1.14.2
ports:
- containerPort: 80 // 这里没有缩进
在k8s pod yaml中,对于command和args字段缩进与不缩进的区别:不缩进加不加引号都行;缩进的话需要加上引号才行,否则会报错。
|
|
注意上面command中的init.sh必须写绝对路径,而且是可执行文件。
chmod a+x init.sh
chmod 755 init.sh
===============================================
k8s pod yaml找不到本地镜像?看看这个:Pull a local image to run a pod in Kubernetes
执行一下
eval $(minikube docker-env)
重新构建镜像。
更多推荐
所有评论(0)