Loading Posts...

How To Configure Kubernetes PODs To Use ConfigMap Data

ConfigMaps can be used to store application configuration artifacts, with the container image and, customize the containerized applications. I thought to write up an article to show, how we can configure Kubernetes PODs to use ConfigMaps data with the containers. Basically, two methods will be discussed in this article.

How To Create A ConfigMaps

First of all, ConfigMap should be created with the parameters. I have created tcKey1= tc-Value-1 and, tcKey2= tc-Value-2, parameters in the ConfigMap, here is the yaml file to create the ConfigMap object .

Create the ConfigMap object with kubectl command pointing the yaml file, ConfigMap object will be created as below

Configure Kubernetes PODs To Use ConfigMap create configmap

Read More: Kubernetes Error: Unable To Connect To The Server Tcp I/O Timeout

Use ConfigMaps To Store Values As Environment Variables

I have deployed a Kubernetes POD with the name of “tc-configmap-pod“, referencing the created ConfigMap. My “tcKey1” value is passed to the “TC_VAR” environmental variable.

Configure Kubernetes PODs To Use ConfigMap env

If you logged in the container shell and echo the “TC_VAR” environmental variable, you can see the value which I passed through the ConfigMap.

Here is the command to access the Container shell

Configure Kubernetes PODs To Use ConfigMap view env

How To Pass ConfigMap Data With A File, And A Mounted Volueme

We can pass the ConfigMap data to the container as a form of a file and a mounted volume. I have created the below yaml file for my POD to mount the ConfigMap, to the “/etc/config” mount location. Volume name would be “tc-config-volume“.

Configure Kubernetes PODs To Use ConfigMap mount

If you access the container shell and check the mount location, two files should be created as below. I have specified two keys in my ConfigMap and two files were created accordingly. Files contained the specified values in the ConfigMap.

Configure Kubernetes PODs To Use ConfigMap view mount volumes

You can directly view the value you specified in the key, with below command

I hope this article will help someone to understand ConfigMaps objects, which can be used in Kubernetes easily.

For More Information:

Aruna Lakmal

Associate Technical Specialist at Pearson, Sri Lanka. Technology junky, enthusiast, a VMware vExpert and a blogger with more than 7 years of Experience in Information Technology more focusing on VMware Virtualization, Microsoft and Datacenter Technologies.

Get Updates Directly To Your Inbox!

   

Leave a Reply

Loading Posts...