Application settings in Kubernetes often need to move independently from container images. A ConfigMap stores non-secret key-value data in the cluster so Pods can receive runtime values without rebuilding the image or hardcoding environment-specific strings.
ConfigMaps are namespaced API objects with data fields for UTF-8 strings and binaryData fields for base64-encoded bytes. kubectl create configmap can build one from literal values, files, directories, or environment-style files; literal values fit small application settings that need a quick cluster-side object.
Passwords, tokens, certificates, and API keys belong in Secrets rather than ConfigMaps. A disposable namespace keeps validation isolated while non-secret keys such as APP_MODE and WELCOME_MESSAGE prove that the ConfigMap exists and that a Pod can read its values.
Related: How to create a Kubernetes Secret
Related: How to create a Kubernetes namespace
$ kubectl create namespace app-config namespace/app-config created
Use the application namespace instead of app-config when adding a real ConfigMap to an existing workload.
Related: How to create a Kubernetes namespace
$ kubectl create configmap web-config --namespace app-config --from-literal=APP_MODE=production --from-literal="WELCOME_MESSAGE=Hello from ConfigMap" configmap/web-config created
Each --from-literal value becomes one key under the ConfigMap data field.
$ kubectl describe configmap web-config --namespace app-config Name: web-config Namespace: app-config Labels: <none> Annotations: <none> Data ==== APP_MODE: ---- production WELCOME_MESSAGE: ---- Hello from ConfigMap BinaryData ==== Events: <none>
apiVersion: v1 kind: Pod metadata: name: configmap-check namespace: app-config spec: restartPolicy: Never containers: - name: configmap-check image: busybox:1.36 command: ["sh", "-c", "echo APP_MODE=$APP_MODE; echo WELCOME_MESSAGE=$WELCOME_MESSAGE; sleep 300"] envFrom: - configMapRef: name: web-config
Keys imported through envFrom must be valid environment variable names. Use a ConfigMap volume mount when the application expects a configuration file instead of environment variables.
$ kubectl apply -f configmap-check-pod.yaml pod/configmap-check created
$ kubectl wait --for=condition=Ready pod/configmap-check --namespace app-config --timeout=90s pod/configmap-check condition met
The short sleep command keeps the test container running long enough for the readiness check and log readback.
$ kubectl logs configmap-check --namespace app-config APP_MODE=production WELCOME_MESSAGE=Hello from ConfigMap
$ kubectl delete namespace app-config namespace "app-config" deleted
Skip this command for a real application namespace. Delete only the test Pod and test ConfigMap if the namespace contains other workloads.