Loading

Quipoin Menu

Learn • Practice • Grow

kubernetes / ConfigMaps
tutorial

ConfigMaps

Applications often need configuration data: environment variables, command‑line arguments, or configuration files. Hard‑coding these in the image is inflexible. ConfigMaps decouple configuration from container images.

What Is a ConfigMap?

A ConfigMap is a Kubernetes object that stores key‑value pairs of configuration data. Pods can consume ConfigMaps as environment variables, command‑line arguments, or as files mounted via volumes.

ConfigMaps separate configuration from container images, making applications portable.

Creating a ConfigMap

From literal values:
kubectl create configmap app-config --from-literal=APP_COLOR=blue --from-literal=APP_MODE=prod
From a file (e.g., app.properties):
kubectl create configmap game-config --from-file=game.properties
From a YAML manifest:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_COLOR: blue
APP_MODE: prod

Using ConfigMap as Environment Variables

In a Pod spec:
apiVersion: v1
kind: Pod
metadata:
name: configmap-pod
spec:
containers:
- name: app
image: busybox
command: ["sh", "-c", "echo $APP_COLOR $APP_MODE; sleep 3600"]
env:
- name: APP_COLOR
valueFrom:
configMapKeyRef:
name: app-config
key: APP_COLOR
- name: APP_MODE
valueFrom:
configMapKeyRef:
name: app-config
key: APP_MODE

Mounting ConfigMap as a Volume

You can mount the entire ConfigMap as a set of files in a volume. Each key becomes a filename, and the value becomes the file content.
volumes:
- name: config-volume
configMap:
name: app-config
containers:
- name: app
volumeMounts:
- name: config-volume
mountPath: /etc/config
Files like /etc/config/APP_COLOR will contain blue.

Updating ConfigMaps

If you update a ConfigMap, the changes are eventually propagated to Pods that use it (depending on how it’s used). For environment variables, you need to restart the Pod. For volumes, kubelet syncs periodically.


Two Minute Drill
  • ConfigMaps store non‑sensitive configuration key‑value pairs.
  • Create from literals, files, or YAML.
  • Inject as environment variables or mounted volumes.
  • Updates propagate but may require Pod restart for env vars.

Need more clarification?

Drop us an email at career@quipoinfotech.com