简体   繁体   English

通过 Kubernetes Deployment.yml 覆盖 Dockerfile 参数

[英]Override Dockerfile arguments by Kubernetes Deployment.yml

I'm running a pipeline on gitlab which uses .gitlab-ci.yml and Dockerfile to build a image and push it to GCP container repository.我在 gitlab 上运行一个管道,它使用 .gitlab-ci.yml 和 Dockerfile 来构建映像并将其推送到 GCP 容器存储库。 Then I use that image to make deployment on Kubernetes.然后我使用该映像在 Kubernetes 上进行部署。

I'm using CI/CD private variables to inject username(service_now_qa_username) and password(service_now_qa_password) and passing it as arguments to docker build command which are then used in Dockerfile我正在使用 CI/CD 私有变量来注入用户名(service_now_qa_username)密码(service_now_qa_password) ,并将其作为参数传递给 docker build 命令,然后在Dockerfile中使用

This is what my gitlab-ci.yml file looks like这就是我的 gitlab-ci.yml 文件的样子

variables:
        BUILD_ARGS: "--build-arg USERNAME=$service_now_qa_username --build-arg PASSWORD=$service_now_qa_password"
script:
   
    - docker build -t "$IMAGE_NAME:$CI_COMMIT_REF_NAME" -t "$IMAGE_NAME:latest" $BUILD_ARGS .

This is what my Dockerfile looks like:这是我的 Dockerfile 的样子:

ARG USERNAME
ARG PASSWORD
ENV USER=$USERNAME
ENV PASS=$PASSWORD

ENTRYPOINT java -jar servicenowapi.jar -conf config.json -username ${USER} -password ${PASS}

Now I want to override these arguments of username and password using Kubernetes Deployment.yml and use Deployment.yaml file to override these arguments.现在我想使用 Kubernetes Deployment.yml覆盖用户名密码的这些参数,并使用 Deployment.yaml 文件覆盖这些参数。

My end goal is to use Kubernetes Deployment.yaml for username and password and passed as arguments to Dockerfile.我的最终目标是使用 Kubernetes Deployment.yaml 作为用户名密码,并作为参数传递给 Dockerfile。

ARGS are build-time variables so no way to pass values to ARGS at runtime. ARGS是构建时变量,因此无法在运行时将值传递给 ARGS。

By the way, you can override entrypoint as following in Kubernetes deployment and consume environment variables.顺便说一句,您可以在 Kubernetes 部署中按照以下方式覆盖entrypoint点并使用环境变量。 ( entrypoint in Dockerfile is command in Kubernetes container spec). (Dockerfile 中的entrypoint点是 Kubernetes 容器规范中的command )。

containers:
  - name: xxxx
    env:
    - name: USER
      value: "Input your user"
    - name: PASS
      value: "Input your pass"
    command: ["java", "-jar servicenowapi.jar -conf config.json -username $(USER) -password $(PASS)"]

The main thing here is to define env vars and to use $() instead of ${} .这里的主要内容是定义环境变量并使用$()而不是${}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Kube.netes manifest deployment.yml 文件中动态或使用变量定义图像名称? - How to define image name in Kubernetes manifest deployment.yml file dynamically or with variables? 如何从kubernetes作业的yml中覆盖Dockerfile的入口点`/ bin / sh`? - How to override Dockerfile's entrypoint `/bin/sh` from kubernetes job's deployment yml? 使用ConfigMap在k8s deployment.yml中填充mountPath - Use ConfigMap to populate mountPath in k8s deployment.yml 通过 Dockerfile 和 Kubernetes 部署通过 env 变量传递 arguments - Passing arguments via env variables through Dockerfile and Kubernetes deployment 通过 Kubernetes 部署 YML 将 arguments 传递给 Docker 容器 - Passing arguments to Docker containers via Kubernetes Deployment YML 通过带有参数的docker run命令覆盖Dockerfile CMD - Override Dockerfile CMD by docker run command with arguments 从 docker-compose.yml 覆盖 Dockerfile ARG - Override Dockerfile ARG from docker-compose.yml 如何在kubernetes部署类中覆盖dnsconfig - How to override dnsconfig in kubernetes deployment kind 在 Kubernetes 中创建部署时引用 Dockerfile 的正确方法是什么? - What is the proper way to reference a Dockerfile when creating a Deployment in Kubernetes? Kubernetes和Dockerfile - Kubernetes and Dockerfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM