Skip to main content
⚑ OpenDevDocs
Kubernetes
devopskubernetesGuideBeginner

Kubernetes ConfigMaps

Decouple non-sensitive configuration parameters, environment variables, and config files from container images using Kubernetes ConfigMaps.

Verified: 2026-10-01
Tested on:kubernetes 1.31
Platforms:
all
#kubernetes#configmaps#configuration#env-vars#12-factor

Kubernetes ConfigMaps

A ConfigMap is an API object used to store non-confidential configuration data as key-value pairs. ConfigMaps allow you to decouple application configuration from container images, following 12-Factor App principles.


1. Creating a ConfigMap

Declarative YAML Manifest

# app-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-settings
  namespace: default
data:
  APP_ENV: "production"
  LOG_LEVEL: "info"
  PORT: "8080"
  app-config.json: |
    {
      "featureFlags": {
        "newDashboard": true,
        "betaCheckout": false
      }
    }

Apply the ConfigMap:

kubectl apply -f app-config.yaml

2. Consuming ConfigMaps in Pods

2.1 As Specific Environment Variables (configMapKeyRef)

apiVersion: v1
kind: Pod
metadata:
  name: api-pod
spec:
  containers:
    - name: api
      image: my-api:latest
      env:
        - name: LOG_LEVEL
          valueFrom:
            configMapKeyRef:
              name: app-settings
              key: LOG_LEVEL

2.2 As Bulk Environment Variables (envFrom)

Injects all keys in the ConfigMap as environment variables:

spec:
  containers:
    - name: api
      image: my-api:latest
      envFrom:
        - configMapRef:
            name: app-settings

2.3 Mounted as Files via Volume Mounts

Mounts app-config.json into /etc/config/app-config.json:

spec:
  containers:
    - name: api
      image: my-api:latest
      volumeMounts:
        - name: config-vol
          mountPath: /etc/config
          readOnly: true
  volumes:
    - name: config-vol
      configMap:
        name: app-settings

On this page