K8s resource: ConfigMap
30 May 2025 (Updated 30 May 2025)
What is ConfigMap?
ConfigMap in Kubernetes is a configuration resource that stores plain-text configuration such as insensitive environment variables app-specific configuration values.
Example ConfigMap YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config
data:
APP_ENV: production
APP_DEBUG: "false"
WELCOME_MESSAGE: "Hello from ConfigMap!"
How to use a ConfigMap in a pod
Method 1: Inject as environment variables
env:
- name: APP_ENV
valueFrom:
configMapKeyRef:
name: my-config
key: APP_ENV
Method 2:
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: my-config
This will create files like /etc/config/APP_ENV
and /etc/config/WELCOME_MESSAGE
inside the pod.
Tagged:
Kubernetes