# ConfigMaps


During this tutorial you'll learn how to manage ConfigMaps on Kubernetes.

  • Level: beginner
  • Requirements: none
  • Previous Tutorials: deployments
  • Can run on Cluster: any
  • Can run on Namespace: any
  • Images used: nginx:alpine

ConfigMaps(opens new window) allow you to decouple configuration from container images, so that your applications are easily portable.


ConfigMaps do not provide secrecy or encryption. If the data you want to store are confidential, use a Secret rather than a ConfigMap.

# Nginx with ConfigMap as Env Variables

We 'll be running an Nginx instance that we'll pass some environment variables, but instead of configuring the environment variables on the same workload (e.g. Deployment) we'll reference them from a ConfigMap.

First let's go and create a ConfigMap with some values.

  • Create ConfigMap
    • Name: nginx-config
    • Data: [COLOR:blue, DAY:monday]

Nginx ConfigMap

Now that we have created the ConfigMap, let's create the Nginx instance and configure two environment variables that take their value from the ConfigMap.

  • Create Deployment
    • Name: nginx
    • Image: nginx:alpine
    • Env: [COLOR:ConfigMap(nginx-config):COLOR, DAY:ConfigMap(nginx-config):DAY]

Once created we can open a terminal and check the environment variables by running env. Their values should appear on screen

$ env

Nginx Deployment with ConfigMap Envs

# Nginx with ConfigMap as Volume

We can also use ConfigMaps as volumes. We'll re-use the previous ConfigMap and create a new deployment

  • Create Deployment
    • Name: nginx-volume
    • Image: nginx:alpine
    • Volumes: [/storage:ConfigMap(nginx-config)]

Once created we can open a terminal and check the path /storage. It should contain two files COLOR and DAY, each one with the content of value.

~ # cd /storage/
/storage # ls
/storage # cat COLOR
/storage # cat DAY

Nginx Deployment with ConfigMap Volume

# Cleanup

Remember to delete the following resources after you finish this tutorial:

  • on active namespace:
    • deployments/nginx
    • deployments/nginx-volume
    • configmaps/nginx-config