简体   繁体   English

如何在舵图中设置 java 环境变量?

[英]How to set java environment variables in a helm chart?

What is the best practice to set environment variables for a java app's deployment in a helm chart so that I can use the same chart for dev and prod environments?在 helm chart 中为 java 应用程序的部署设置环境变量的最佳实践是什么,以便我可以对 dev 和 prod 环境使用相同的图表? I have separate kubernetes deployments for both the environments.我对这两种环境都有单独的 kubernetes 部署。

spec:
    containers:
        env:
           - name: SYSTEM_OPTS
           - value: "-Dapp1.url=http://dev.app1.xyz -Dapp2.url=http://dev.app2.abc ..."

Similarly, my prod variables would something like同样,我的 prod 变量类似于

"-Dapp1.url=http://prod.app1.xyz -Dapp2.url=http://prod.app2.abc ..."

Now, how can I leverage helm to write a single chart but can create separated set of pods with different properties according to the environment as in现在,我如何利用 helm 编写单个图表,但可以根据环境创建具有不同属性的独立 pod 集,如

helm install my-app --set env=prod ./test-chart

or或者

helm install my-app --set env=dev ./test-chart

The best way is to use single deployment template and use separate value file for each environment.最好的方法是使用单个部署模板并为每个环境使用单独的值文件。 It does not need to be only environment variable used in the application.它不需要只是应用程序中使用的环境变量。 The same can be apply for any environment specific configuration.这同样适用于任何特定于环境的配置。

Example:例子:

deployment.yaml部署.yaml

spec:
    containers:
        env:
           - name: SYSTEM_OPTS
           - value: "{{ .Values.opts }}"

values-dev.yaml值-dev.yaml

# system opts
opts: "-Dapp1.url=http://dev.app1.xyz -Dapp2.url=http://dev.app2.abc "

values-prod.yaml values-prod.yaml

# system opts
opts: "-Dapp1.url=http://prod.app1.xyz -Dapp2.url=http://prod.app2.abc "

Then specify the related value file in the helm command.然后在 helm 命令中指定相关的值文件。

For example, deploying on dev enviornemnt.例如,在开发环境中部署。

helm install -f values-dev.yaml my-app ./test-chart

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM