k8s 有两个参数commond args对应是Dockerfile 的Entrypoint CMD
如果yaml 中设置了参数会替换掉Dockerfile的参数。

Entrypoint	 CMD	    K8S command	          K8S args	                 最后执行情况
echo	    test	    空	                  空	                     echo test
echo	    test	    test1                 空	                     test1
echo	    test	    空	                  test2                      echo test2
echo	    test	    test1	              test2                      test1 test2

我们以docker 的nginx 为例:
可以通过history 观察到镜像最后一个cmd为nginx -g ---- 是以前台运行nginx的一个命令。
在这里插入图片描述
构建k8s的pod 如下:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    command: ["/bin/echo"]
    args: ["test"]

在这里插入图片描述
所以想要替换镜像中的启动参数,只需要在yaml文件中修改对应的参数即可。

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

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐