Member-only story
ENV variables in Kubernetes (Config Maps)
Lets discuss how to set an environment variables in Kubernetes.
In a POD definition file, we can use ENV property. ENV is an array. So every item under ENV property start with a dash (-) indicating an item in the array. Each item has name and value property. The name is the name of the environment variable and the value is its value as name suggests.
env:
- name: VARIABLE1
value: TEST
This is direct way of specifying the environment variables using the plain key-value pair.
However there are other ways of setting the environment variables such as using config maps and secrets. The difference in this case is that instead of specifying the value, we say valueFrom and then specification.
We will discuss about Config Maps in this article.
Config Maps
When we add all the environment variables in POD definition file, it will become difficult to manage. Imagine you have many POD definition files and have same set of environment variables, then it will be nightmare to manage all of them.
We can take it out from POD definition file and manage in central file. This is where ConfigMaps comes in to place. We inject the config map when the POD is created. So the key-value pairs are available as environment variables. Thus the application deployed in the container inside the POD can consume them.