Kubernetes ConfigMaps explained: Create, mount and use them
Learn how to create Kubernetes ConfigMaps and use them in three ways: as environment variables, with envFrom, and as volume mounts. Includes working YAML examples.
4 lessons · 10 min · Advanced
Written by
Marketing Team at Civo
Written by
Marketing Team at Civo
ConfigMaps let you separate configuration data from your container images. Instead of baking environment-specific values into your image, you store them in a ConfigMap and inject them at runtime. This means the same image can run in development, staging, and production with different configuration, without rebuilding.
ConfigMaps are for non-sensitive data. For passwords, tokens, and certificates, use Secrets instead.
Create a ConfigMap
From a literal value:
kubectl create configmap demo --from-literal=name=saiyam
From a file:
kubectl create configmap test --from-file=file.prop
From an environment file (multiple key-value pairs as separate data entries):
kubectl create configmap test2 --from-env-file=env.prop
View all ConfigMaps:
kubectl get configmap
Inspect a ConfigMap:
kubectl describe configmap demo
Expected output:
Name: demoNamespace: defaultData====name:----saiyam
Three ways to consume a ConfigMap
Pattern 1: reference a specific key as an environment variable
apiVersion: v1kind: Podmetadata:name: demospec:containers:- name: busyboximage: busyboxcommand: ["env"]env:- name: HELLOvalueFrom:configMapKeyRef:name: demokey: namerestartPolicy: Never
kubectl create -f demo.yamlkubectl logs demo
Expected output:
HELLO=saiyam
Pattern 2: load all keys as environment variables with envFrom
Use envFrom when you want every key in the ConfigMap available as an environment variable without listing them individually:
apiVersion: v1kind: Podmetadata:name: demo-envfromspec:containers:- name: busyboximage: busyboxcommand: ["env"]envFrom:- configMapRef:name: demorestartPolicy: Never
kubectl create -f demo-envfrom.yamlkubectl logs demo-envfrom
All keys from the demo ConfigMap will appear as environment variables in the container output.
Pattern 3: mount a ConfigMap as a volume
When your application reads configuration from files on disk, mount the ConfigMap as a volume. Each key in the ConfigMap becomes a file at the mount path, with the value as the file contents.
First, create a ConfigMap with multiple keys:
apiVersion: v1kind: ConfigMapmetadata:name: app-configdata:file1: |setting1=value1setting2=value2file2: |debug=truelog_level=info
kubectl apply -f cm-for-volume.yaml
Then mount it into a pod:
apiVersion: v1kind: Podmetadata:name: cm-volumespec:containers:- name: busyboximage: busyboxcommand: ["ls", "/etc/config"]volumeMounts:- name: config-volumemountPath: /etc/configvolumes:- name: config-volumeconfigMap:name: app-configrestartPolicy: Never
kubectl create -f demo2.yamlkubectl logs cm-volume
Expected output:
file1file2
Each key from the ConfigMap appears as a file at /etc/config. The value of each key is the file contents.
ConfigMaps as a volume type
ConfigMaps and Secrets are treated as ephemeral volume types in Kubernetes. They appear in the pod's volumes spec just like any other volume type, alongside emptyDir, hostPath, and PersistentVolumeClaims. The key difference is that their contents come from cluster objects rather than from the node filesystem or a storage backend.
This means you can mix ConfigMap volumes with other volume types in the same pod spec. A pod might mount a ConfigMap for configuration files, a Secret for certificates, and a PersistentVolumeClaim for application data, all in the same volumes section.
One important behaviour: when a ConfigMap is mounted as a volume, Kubernetes updates the files automatically when the ConfigMap changes, typically within 60 seconds. Environment variables set from ConfigMaps at pod startup do not update without a pod restart.

Marketing Team at Civo
Civo is the Sovereign Cloud and AI platform designed to help developers and enterprises build without limits. We bridge the gap between the openness of the public cloud and the rigorous security of private environments, delivering full cloud parity across every deployment. As a team, we are dedicated to providing scalable compute, lightning-fast Kubernetes, and managed services that are ready in minutes. Through CivoStack Enterprise and our FlexCore appliance, we empower organizations to maintain total data sovereignty on their own hardware.
Our mission is to make the cloud faster, simpler, and fairer. By providing enterprise-grade NVIDIA GPUs and streamlined model management, we ensure that high-performance AI and machine learning are accessible to everyone. Built for transparency and performance, the Civo Team is here to give you total control over your infrastructure, your data, and your spend.
Share this lesson