Skip to main content
In this lesson you’ll learn how to manage application configuration in Kubernetes using ConfigMaps. ConfigMaps let you separate non-sensitive configuration from Pod specs so you can manage settings centrally, avoid duplication across manifests, and make your deployments more maintainable.
A presentation slide titled "ConfigMaps" with a large dark-blue curved panel on the right featuring a white gear-and-wrench icon. The left side is mostly white with the "ConfigMaps" text centered and a small copyright notice at the bottom.
Why use ConfigMaps?
  • Reduce duplication of environment variables across many Pod manifests.
  • Separate configuration from container images and deployment logic.
  • Make configuration updates without rebuilding container images (depending on consumption method).
Basic workflow
  1. Create a ConfigMap that contains key/value configuration data.
  2. Inject the ConfigMap into one or more Pods as environment variables or mounted files.
Example key-value pairs we want to manage:
Example: embedding env vars directly (NOT recommended at scale)
When managing many manifests, duplicating values like the example above becomes hard to maintain. ConfigMaps solve this. Ways to create ConfigMaps There are two main approaches: imperatively with kubectl and declaratively with YAML manifests. Imperative creation (from literals)
  • Use --from-literal to add key/value pairs directly.
Repeat --from-literal for additional keys. Good for a small number of items; less practical for many entries. Imperative creation (from files)
  • Use --from-file to create keys from file names. The file content becomes the value.
If app.properties contains arbitrary content, the ConfigMap stores it under the key app.properties. Declarative creation (YAML manifest)
  • Preferred for repeatability and GitOps workflows. Create app-config.yaml:
Apply the manifest:
You can create multiple ConfigMaps (for example mysql-config, redis-config) and name them to reflect their purpose. View and inspect ConfigMaps
  • List ConfigMaps:
Sample output:
  • Describe a specific ConfigMap to inspect keys and values:
Sample output:
How to inject ConfigMap data into Pods There are three common consumption patterns. Choose the one that best fits your application:
  1. Import all keys into environment variables (envFrom)
  • Use envFrom to import all key-value pairs from the named ConfigMap into the container environment:
This populates APP_COLOR=blue and APP_MODE=prod in the container environment.
  1. Map a single key to a single environment variable
  • Use valueFrom.configMapKeyRef when you only need one specific key:
  1. Mount ConfigMap keys as files in a volume
  • Mount the ConfigMap as a volume so that each key appears as a file under the mount path:
Files appear at /etc/config/APP_COLOR and /etc/config/APP_MODE, with file contents equal to the values. Best practices and important notes
ConfigMaps are not intended for sensitive data (such as passwords). Use Secrets for sensitive configuration. Also prefer declarative manifests (kubectl apply -f) for repeatability and version control.
Quick tips
  • Use clear, descriptive ConfigMap names because Pods reference them by name.
  • Prefer declarative YAML for production and CI/CD pipelines.
  • When mounting ConfigMaps as files, applications that read filesystem-based configs can pick up changes if they re-read files (watching/reload behavior varies by app).
  • To update a ConfigMap and ensure Pods pick up changes, you may need to restart or roll the Pods (depending on how the app consumes the data).
What we covered
  • Why separate configuration from Pod manifests.
  • How to create ConfigMaps imperatively (--from-literal, --from-file) and declaratively (YAML).
  • How to view and describe ConfigMaps (kubectl get / kubectl describe).
  • How to inject ConfigMap data into Pods using envFrom, valueFrom.configMapKeyRef, and volume mounts.
Links and references Try it
  1. Create a ConfigMap using the YAML manifest above.
  2. Create the example Pod that consumes the ConfigMap.
  3. Inspect the Pod environment or mounted files to confirm the ConfigMap values are available.

Watch Video

Practice Lab