In this post, I’m covering ConfigMaps in Kubernetes. I assume you have a basic understanding of Kubernetes and its use cases as well as pods.

To follow along with the demo, you will need kubectl and minikube installed.

What is a ConfigMap?

When working with 12 factor apps, one of the factors is configs. That means, when you’re dealing with microservices, you must figure out how your configurations will be applied.

If you want to deploy to multiple environments, like stage, dev, and prod, it’s a bad practice to bake the configs into the application because of environment differences. Ideally, you’ll want to separate configurations in order to match the deploy environment. This is where ConfigMap comes into play.

ConfigMaps allow you to decouple configuration artifacts from image content. This allows K8S to make your containerized application portable without you needing to worry about configurations. Both users and system components are able to store config data in ConfigMap.

ConfigMap is somewhat similar to secrets, but it provides a way of working with strings that don’t contain sensitive information.

How to create ConfigMap

Creating a ConfigMap is fairly simple and straightforward. You can create it with directories, files, or literal values. We’ll demonstrate each: the rest of the blog post will use a simple example to demonstrate how to work with a ConfigMap.

Create ConfigMap from a directory

To create ConfigMap from a directory, you must first create or have an existing directory with your configs there.

$ mkdir configmap-demo 

Now, wget the configs into our ConfigMap demo directory.

$ wget -O configmap-demo
$ wget -O configmap-demo

We then downloaded test config files into our directory, which we can create a ConfigMap from—it will have all the files we downloaded.

$ kubectl create configmap demo-configmap --from-file=configmap-demo
configmap "demo-configmap" created

If we describe our ConfigMap, we will see both files as data entries with their contents.

$ kubectl describe configmap demo-configmap
Name:         demo-configmap
Namespace:    default
Labels:       <none>
Annotations:  <none>


Events:  <none>

Create ConfigMap from a file

Creating from a file is very similar to creating from a directory. All you’ll need to do is pass in the name of the file to –from-file argument. When creating ConfigMap this way, you can pass in as many files as you want to the –from-file argument and it will add it to the ConfigMap.

Create ConfigMap from a literal value

Creating ConfigMap this way mean you can specify your configuration directly from command line without creating any file or directory. For example kubectl create ConfigMap special-config – –from-literal=special.type=charm. You can have multiple key-value pairs if needed.

Using ConfigMap in a pod

Let’s create a test ConfigMap:

$ kubectl create configmap special-config
configmap "special-config" created

Then create a pod to use the configmap as an env variable.


apiVersion: v1
kind: Pod
  name: configmap-demo-pod
    - name: test-container
      command: [ "/bin/sh", "-c", "env" ]
        # Define the environment variable
        - name: SPECIAL_LEVEL_KEY
              # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
              name: special-config

              # Specify the key associated with the value
  restartPolicy: Never
$ Kubectl create -f demo-pod.yaml
pod "configmap-demo-pod" created

We can now see that there is an environment variable set in the pod with our defined configmap value.

$ kubectl logs configmap-demo-pod | grep SPECIAL_LEVEL_KEY

Kubernetes On-Demand Webinar

Kubernetes (K8S), containers, microservices… what’s missing? Application Workflows! Watch this On-Demand Webinar to learn about K8S JOB and DaemonSet objects and much more!
Watch Now ›
Last updated: 01/31/2019

These postings are my own and do not necessarily represent BMC's position, strategies, or opinion.

See an error or have a suggestion? Please let us know by emailing

Run and Reinvent Your Business with BMC

From core to cloud to edge, BMC delivers the software and services that enable nearly 10,000 global customers, including 84% of the Forbes Global 100, to thrive in their ongoing evolution to an Autonomous Digital Enterprise.
Learn more about BMC ›

About the author

Toye Idowu

Toye Idowu

Olatoye is a Certified Kubernetes Administrator and experienced DevOps/Platform engineering Consultant with a demonstrated history of working in the Information Technology and Services industry.