Overview
TheConfigMap class represents a Kubernetes ConfigMap, which holds configuration data for pods to consume. ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable.
Class Definition
v1
Constructor
ConfigMap accepts all parameters from NamespacedResource, plus:dict[str, Any] | None
Binary data to store. Each key must consist of alphanumeric characters, ’-’, ’_’ or ’.’. BinaryData can contain byte sequences that are not in the UTF-8 range. Keys must not overlap with the
data field.dict[str, Any] | None
Configuration data to store. Each key must consist of alphanumeric characters, ’-’, ’_’ or ’.’. Values with non-UTF-8 byte sequences must use the
binary_data field. Keys must not overlap with the binary_data field.bool | None
If set to true, ensures that data stored in the ConfigMap cannot be updated (only object metadata can be modified). If not set, the field can be modified at any time. Defaults to nil.
Properties
keys_to_hash
["data", "binaryData"]
Inherited Methods
ConfigMap inherits all methods from NamespacedResource and Resource.Examples
Creating a Simple ConfigMap
Creating a ConfigMap with File-like Data
Creating an Immutable ConfigMap
Creating a ConfigMap with Binary Data
Creating a ConfigMap from Multiple Sources
Using ConfigMap in a Pod (Volume Mount)
Using ConfigMap in a Pod (Environment Variables)
Updating a ConfigMap
Listing ConfigMaps
Using Context Manager
Creating from YAML
Best Practices
Size Limitations
ConfigMaps are stored in etcd and should not be used for large amounts of data. The recommended maximum size is 1 MiB per ConfigMap.Immutability
For production environments, consider making ConfigMaps immutable to:- Prevent accidental updates
- Improve performance (kubelet doesn’t need to watch for changes)
- Ensure consistency across pod restarts
Mounting as Files
When mounting ConfigMaps as volumes:- Each key becomes a file in the mount directory
- File permissions default to 0644
- Updates to the ConfigMap are reflected in mounted volumes (after a sync period)
Environment Variables
When using ConfigMaps as environment variables:- Updates to the ConfigMap do NOT automatically update pod environment variables
- Pods must be recreated to pick up new values
See Also
- NamespacedResource - Base class
- Secret - For sensitive configuration data
- Pod - For using ConfigMaps in workloads
- Kubernetes ConfigMaps - Official documentation