Key Concepts
ConfigMap
A Kubernetes resource that stores configuration data as key-value pairs.
Data
String key-value pairs for configuration files, environment variables, or command arguments.
Binary Data
Base64-encoded binary content for non-UTF8 data like images or certificates.
Mounting
ConfigMaps can be mounted as volumes or exposed as environment variables in pods.
Required Permissions
| Action | Permission |
|---|---|
| View configmaps | iam:project:infrastructure:kubernetes:read |
| Create configmap | iam:project:infrastructure:kubernetes:write |
| Edit configmap | iam:project:infrastructure:kubernetes:write |
| Delete configmap | iam:project:infrastructure:kubernetes:delete |
How to View ConfigMaps
How to View ConfigMap Details
How to Create a ConfigMap
Write YAML
Enter the ConfigMap manifest in YAML format. Key fields:
data- String key-value pairsbinaryData- Base64-encoded binary content
How to Edit a ConfigMap
Modify Data
Edit the ConfigMap content. Common changes:
- Add or update configuration keys
- Modify values
- Update labels and annotations
How to Delete a ConfigMap
Using ConfigMaps in Pods
As Environment Variables
As Volume Mounts
With Specific Keys
ConfigMap Size Limits
| Limit | Value |
|---|---|
| Maximum size | 1 MiB (1,048,576 bytes) |
| Key name length | 253 characters |
| Key name pattern | Alphanumeric, -, _, . |
The 1 MiB limit applies to the total size of all data in a single ConfigMap. For larger configurations, split into multiple ConfigMaps or consider using external configuration storage.
Data vs Binary Data
| Field | Use Case | Encoding |
|---|---|---|
| data | Text files, properties, JSON, YAML | UTF-8 string |
| binaryData | Images, certificates, compressed files | Base64 encoded |
Troubleshooting
Pod fails to start with ConfigMap error
Pod fails to start with ConfigMap error
- Verify the ConfigMap exists in the same namespace as the pod
- Check ConfigMap name spelling in pod spec
- Ensure referenced keys exist in the ConfigMap
- Check for optional flag if ConfigMap might not exist
Configuration changes not reflected in pod
Configuration changes not reflected in pod
- ConfigMap updates don’t automatically restart pods
- Restart the deployment/pod to pick up changes
- Use
subPathmounts prevent automatic updates - Consider using reloader controllers for automatic restarts
ConfigMap too large
ConfigMap too large
- ConfigMaps are limited to 1 MiB
- Split large configurations into multiple ConfigMaps
- Consider using external configuration storage
- Compress data if appropriate
Invalid key name
Invalid key name
- Keys must be alphanumeric with
-,_, or. - Keys cannot start with
.. - Maximum length is 253 characters
- Avoid special characters and spaces
Binary data not working
Binary data not working
- Ensure binaryData values are base64 encoded
- Don’t mix the same key in both data and binaryData
- Verify encoding with
base64 -dcommand
Permission denied reading mounted ConfigMap
Permission denied reading mounted ConfigMap
- Check file permissions in the ConfigMap volume
- Use
defaultModeto set permissions (e.g.,0644) - Verify container runs with appropriate user
FAQ
What's the difference between ConfigMaps and Secrets?
What's the difference between ConfigMaps and Secrets?
ConfigMaps store non-sensitive configuration data in plain text. Secrets store sensitive data (passwords, tokens) with base64 encoding and additional security features like encryption at rest. Use Secrets for sensitive data, ConfigMaps for everything else.
Do pods automatically update when ConfigMaps change?
Do pods automatically update when ConfigMaps change?
No. Pods don’t automatically restart when ConfigMaps change. Volume-mounted ConfigMaps eventually update (kubelet sync period), but environment variables never update. Restart pods or use a reloader controller for automatic updates.
Can I use ConfigMaps across namespaces?
Can I use ConfigMaps across namespaces?
No. ConfigMaps are namespace-scoped. A pod can only reference ConfigMaps in its own namespace. For shared configuration, create identical ConfigMaps in each namespace or use cluster-level configuration tools.
How do I create a ConfigMap from a file?
How do I create a ConfigMap from a file?
Use kubectl:
kubectl create configmap my-config --from-file=config.properties. This creates a key with the filename and value with the file content.Can I have multiple files in one ConfigMap?
Can I have multiple files in one ConfigMap?
Yes. Add multiple keys to the data section. When mounted as a volume, each key becomes a file in the mount directory.
What happens if a required ConfigMap doesn't exist?
What happens if a required ConfigMap doesn't exist?
The pod will fail to start with a “CreateContainerConfigError”. Use
optional: true in the volume or envFrom to allow the pod to start without the ConfigMap.How do I mount only specific keys from a ConfigMap?
How do I mount only specific keys from a ConfigMap?
Use the
items field in the volume definition to select specific keys and optionally rename them with the path field.Can I edit ConfigMap data in the UI?
Can I edit ConfigMap data in the UI?
Yes. Use the Edit ConfigMap action to modify the YAML, including data values. Changes take effect immediately but pods need to be restarted to pick up the changes.