[k8s] command和args

k8s中的command和args可以覆盖docker镜像中的Entrypoint和Cmd。其中,k8s的command可以覆盖docker镜像中的Entrypoint,k8s的args可以覆盖docker镜像中的Cmd。参考 Difference between Docker ENTRYPOINT and Kubernetes container spec COMMAND?

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.

了解一下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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值