Dolphin
Dolphin

Reputation: 38607

how to define and share pods environment variable to pod's apps in kubernetes

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?

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

2.if I choose application.properties,I should keep application-develop.properties/application-test.properties.....

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

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).

Upvotes: 0

Views: 534

Answers (1)

Burak Serdar
Burak Serdar

Reputation: 51467

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:

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

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.

Upvotes: 2

Related Questions