<p>I am deploying some apps in kubernetes,and my apps using a config management tool called apollo.This tool need to define the apps running environment(develop\test\production......) through this ways:1.java args 2.application.properties 3./etc/settings/data.properties. Now I am running apps in Kubernetes,the question is,how to define running environment variable?</p>

<p>1.if I choose java args,so I should keep some scripts like: <code>start-develop-env.sh/start-test-env.sh/start-pro-env.sh</code></p>

<p>2.if I choose <code>application.properties</code>,I should keep <code>application-develop.properties/application-test.properties</code>.....</p>

<p>3.if I choose <code>/etc/settings/data.properties</code>,It is impossible to login every docker container to define the config file of each environment.</p>

<p>what is the best way to solve the problem? write in kubernetes deployment yaml and my apps could not read it(define variable in batch pods collections in one place is better).</p>

Dolphin
<p>You can implement #2 and #3 using a configmap. You can define the properties file as a configmap, and mount that into the containers, either as application.properties or data.properties. The relevant section in k8s docs is:</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/</a></p>

<p>Using java args might be more involved. You can define a script as you said, and run that script to setup the environment for the container. You can store that script as a ConfigMap as well. Or, you can define individual environment variables in your deployment yaml, define a ConfigMap containing properties, and populate those environment variables from the configmap. The above section also describes how to setup environment variables from a configmap.</p>
