Injecting ConfigMap and Secret Data Into Pods and Containers

Learn how to inject ConfigMap and secret data into Pods and containers.

You’ve seen how to imperatively and declaratively create ConfigMap objects and populate them with data. Now let’s see how to get that data into applications running in containers.

There are three main ways to inject ConfigMap data into a container:

  • As environment variables
  • As arguments to container startup commands
  • As files in a volume

Let’s look at each.

ConfigMaps and environment variables

A common way to get ConfigMap data into a container is via environment variables. You create the ConfigMap, then you map its entries into environment variables in the container section of a Pod template. When the container is started, the environment variables appear in the container as standard Linux or Windows environment variables.

The figure below shows this:

Get hands-on with 1200+ tech skills courses.