We are using Kubernetes v1.1.0-beta and I am curious if Kubernetes supports env_file
, like Docker Compose? On Pod/ReplicationController creation it would read in the file specified by env_file and set the variables on that pod. Is this a thing or just env
map?
![](../../users/profiles/140501.webp)
- 2,575
- 2
- 14
- 17
2 Answers
No. Kubernetes does not support evv_file
as of now. You will have to specify key=value
pairs for env variables.
![](../../users/profiles/319623.webp)
- 121
- 1
-
this really scares me how people are working with this beast.. if you need to run migrations before launching containers, what will you do?? write 20 env variables from CLI when using kubectl-run? this is freaking INSANE. – holms Sep 18 '16 at 16:41
-
@holms You should probably be storing all of your configurations in yaml or json files to reduce the complexity of running kubectl commands. – Eric Uldall Nov 18 '16 at 17:59
-
@EricUldall I'm storing in yaml files, the only thing is that before that version I've specified kubernetes had docs where they have 10 variants how to use global variables, and in this specified version it doesn't work anymore. So I've post-postponed kubernetes for now, there's too much complexity for me in there, and it's not explicit as docker-compose with docker-swarm are – holms Dec 21 '16 at 22:56
-
@holms if you're trying to get data on the machine for app configuration, another good option is a configMap. http://kubernetes.io/docs/user-guide/configmap/ You could in theory write a configMap this is just an env file and then source that file when your pod starts, if you wanted to. Otherwise you can just mount the configMap to a place on disk that can be accessed by the app (/srv/config/myMap.json, /srv/config/myMap.yaml, etc...) – Eric Uldall Jan 03 '17 at 17:39
You can use a config map to achieve this. So you deploy a configmap with the key value pairs you want, this stays stable across deployments. You can even deploy multiple config maps, so you could have different values for different environments.
Then in your pod yaml file, you would do something like this to expose the configmap values as an env variable
env:
# Define the environment variable
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
# The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
name: special-config
# Specify the key associated with the value
key: special.how
Read more here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-using-configmap-data
If there is any sensitive data (like passwords, db connection URIs etc), you should use secrets instead. Unlike configmaps, secrets are obscured.
More info here -> https://kubernetes.io/docs/concepts/configuration/secret/
![](../../users/profiles/503606.webp)
- 116
- 1
- 9