Kubernetes 101 : ConfigMaps and environmental variables

Configmaps allow us to separate kubernetes resources like the pods from their configuration.
Separating a pod for example from its configuration gives us the flexibility to have different "flavors" of the same resource.

If we code the configuration inside a kubernetes resource, we would need to create a new the resources from scratch for each "flavor" instead of just attaching a new configuration to it.

Creating a configmap:

We can use the below command to create a configmap:

source: is the directory, file, or value we get the configuration data from.


We can use more than one variable as we can see below:

 --from-literal=value-1=one  --from-literal=value-2=two

Creating a configmap from a file:

We can use the below command to create a configmap from the file "config_1.conf"

The file is composed of data in the form of key, value pairs.

Getting a variable from a configmap in the Yaml file:

To pass arguments to containers, we could pass them on the command line, we could also put these arguments in a file and pass the file to the command line (as a parameter).


To access the configuration files that live outside of the containers, we would need to mount the host folder containing the configuration file into the container.
Another way is to use environmental variables.

Configmap Yaml file:

A configmap is a kubernetes resource that could be created using  a Yaml configuration file. 

Below is an example of a configmap in a Yaml file "config.yaml":

We then create the configmap using the below command:


Leave as a comment: