Kubernetes 101 : An overview of configMaps



A configMap is a kubernetes object for storing information that is not sensitive. 
Sensitive data like passwords, TLS keys or certificates, would go into another kubernetes object called "Secret".

ConfigMaps allow us to have copies of the same image linked to different environmental variables for example.
We don't need to build different images with different environmental variables, we just build one image and attach the copies of the image to different configMaps.


The environmental variables that change from image to image would go into a config file. 
The "static" data that doesn't change are usually built inside the image.

Creating the configMaps:

We can create a configMap using the below command:


Format of the "variables.conf" file:



Creating a configMap file with a configuration key:

Below is the command for creating a configMap from a file with a configuration key (data-key) that will go into the Yaml file:


As a result, we would get the below configuration file:


"|" treats the block as a sequence, rather than individual variables

Creating a configMap from literal values:

The below command creates a configMap "config_1" from a literal value:


Pods get access to configMaps through either environmental variables or through a volume mounted on to the pod (onto the container's filesystem). 

Access through environmental variables:

Below is the Yaml configuration file of the pod with a reference to the configMap "configmap_1":


And below is the corresponding configMap 
"configmap_1":


Comments

Leave as a comment:

Archive