Difficulty: intermediate
Estimated Time: 15-20 minutes

Digital Academy Logo

Welcome to the Digial Academy's "Kubernetes Fundamentals" series. This is Module 2 - Introduction to ConfigMaps.

In this lab, we will decouple configuration from applications with Kubernetes ConfigMaps.

ConfigMaps are a way to decouple configuration from application source code and Kubernetes Pods / Deployment files. If you are familiar with 12-Factor App principles, then this addresses factor 3: "Store config in the environment."

ConfigMaps allow you to independently store data that your application needs in a Kubernetes object. ConfigMaps are decoupled from Pods and Deployments. In addition, ConfigMaps can be consumed by multiple Pods and Deployments, which can be extremely useful. As an example, if you have multiple microservies that need access to the same configuration parameter, all it takes is a single ConfigMap. This used to be accomplished with a Config-Server microservice, or supplying each microservice with the same environment variable, which made updates difficult.

We will go through the process of creating ConfigMaps from literal values, files, and directories. We'll supply these values to Pods as environment variables, and finally create a simple Redis Deployment configured via ConfigMaps.

For more information, see the Kubernetes documentation.

Developer(s): William Hearn and Zachary Seguin

Congratulations, you now have an understang of Kubernetes ConfigMaps next we will be taking a look at Kubernetes Secrets.

ConfigMaps

Step 1 of 6

Create ConfigMaps from Literal Values

ConfigMaps are Kubernetes objects that store configuration external to source code.

Creating a ConfigMap is easy:

kubectl create configmap <configmap-name> <data>

The <data> used to populate the ConfigMap can be from a variety of different formats. For testing purposes, the easiest way to supply this is with literals.

Literals refers to data you enter in on the command line.

For example:

kubectl create configmap my-config --from-literal=course="Kubernetes Fundamentals"

Now that the ConfigMap is created we can view it with:

kubectl get configmaps

We can inspect the contents with:

kubectl describe configmap my-config

We can get an even better view with:

kubectl get configmap my-config -o yaml

You can also provide multiple values to a ConfigMap:

kubectl create configmap multi-config --from-literal=name.first=David --from-literal=name.last=Widen --from-literal=age=28 --from-literal=hometown="Glen Cove"

And get an even better view with:

kubectl get configmap multi-config -o yaml