ConfigMap
ConfigMap is used to store non-sensitive information as key-value pairs. Pods can consume ConfigMaps via environment variables, command-line arguments, or volume mounts.
ConfigMap decouples environment-specific configuration from your application code, which improves application portability.
Note that ConfigMap does not provide any encryption.
How to Write a ConfigMap Object
Below is an example of a ConfigMap object:
1 | apiVersion: v1 |
Like every other Kubernetes API object, a ConfigMap has apiVersion, kind, and metadata fields, but it does not have a spec field. ConfigMap provides two fields — data and binaryData — for storing configuration data.data: Stores configuration data. Values must contain only UTF-8 encoded data; non-UTF-8 data must use binaryData instead.binaryData: Stores binary data.
There is also an immutable field that specifies whether the data stored in a ConfigMap can be modified.
Note that keys within the same ConfigMap must be unique. A key already used in data cannot be used in binaryData, and vice versa.
How to Use a ConfigMap
Containers in a Pod can consume a ConfigMap in four ways:
- As command-line arguments to the container’s entrypoint
- As environment variables for the container
- As a read-only volume
- By reading the ConfigMap directly via the Kubernetes API from within the application
Below is a simple example (also uploaded to GitHub):
1 | apiVersion: v1 |
Results:
- Verify the environment variable

- Verify the read-only file
