Managing Application configuration with Kubernetes Pods

Gaurav Kaushik
3 min readMay 15, 2021
Different Applications deployed on Kubernetes Pods

As a user, when you are running applications in Kubernetes, you may want to pass dynamic values to your applications at runtime to control the way how they behave.
This is known as Application configuration.

Two types of application Configuration are:
1) ConfigMaps
2) Secret

With ConfigMaps, one can store Configuration data in Kubernetes . ConfigMaps store data in the form of a key-value map. ConfigMap data can be passed to user’s container applications.

Simple example of a ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
name: sales-dev
data:
key1: value1
key2: value2
key3:
subkey:
morekeys: data

Secrets are similar to ConfigMaps but are designed to store sensitive data, such as passwords or API keys, more securely. They are created & used similarly to ConfigMaps.

Simple example of Secrets:

apiVersion: v1
kind: Secret
metadata:
name: sales-creds
type: Opaque
data:
username: YWRtaW4=
password: YWRtaW4xMjM=

To pass the Application configuration(ConfigMaps & Secrets) to the containers there are two ways:

1) via Environment Variables: User can pass ConfigMap & Secret data to their containers as Environment Variables. These variables will be visible to the Container process at runtime.

2) via Configuration Volumes: Configuration data from ConfigMaps & Secrets can also be passed to containers in the form of mounted volumes. This will cause the config data to appear in files available to the container file system.
Each top-level key in the configuration data will appear as a file containing all keys below that top-level key.

Let us try a hands-on on the above two:
via Environment Variables-

  1. Create a ConfigMap with the following content:

2. Create the config map & verify the content:

3. Similarly create a Secret

Create these values & then append in the yml file

4. Now, create a pod & apply:

Now, if you check the logs for this pod, you will observe the values which were defined in the ConfigMap & Secret:

This proves the case for the ‘Environment Variables’ way of passing Application Configuration data to the containers(Application)

via Configuration Volumes-
1. Create a pod with the following content:

2. Add Volume mount to set the mountPath:

3. Create the Pod & check the config data:

The same data will be displayed which was created as a part of ConfigMap & Secret earlier

So, this was the second way of passing ConfigMap & Secret to the user Applications.

In the next post, we will understand on how to manage Container resources.
Thank You!

--

--