Open In App

Kubernetes – Create Config Map From Files

Pre-requisite: Kubernetes

While creating a manifest file in Kubernetes, we can define environment variables. However, when you have a lot of manifest files, it will become difficult to manage the environment data stored in various manifest files. To overcome this issue, we can manage environment data centrally using ConfigMaps.



ConfigMaps are used to pass configuration data in the form of key-value pairs in Kubernetes. Let’s say when a pod is created, ConfigMap is injected into that pod so that key-value pairs are available as environment variables for applications hosted inside the container in the pod.

There are two phases involved in configuring ConfigMaps:



1. Create ConfigMap Using Definition File:

You can use a definition/manifest file to create a ConfigMap and store environment variables. In the case of manifest files, we generally have a spec field whereas, in the case of a ConfigMap, we have a data or binary data field. The keys stored in the data field should not have a duplicate in the binary data field.

Manifest file for ConfigMap

 

creating a manifest file on Kubernetes

checking env variables

environment variables in migration.properties

envs/migration.properties

Creating ConfigMap using a file 

ConfigMaps from files

2. Inject ConfigMap in Manifest Files:

Now that we have the ConfigMap created, we need to inject it into our pod definition file. There are 3 ways to inject ConfigMaps in our pod definition file listed as follows:

Injecting a ConfigMap

Injecting a single environment variable from ConfigMap

Injecting a file from the volume

Article Tags :