Skip to main content
K8sCalc

kubernetes

Kubernetes ConfigMap Generator

Generate a Kubernetes ConfigMap YAML from key-value pairs. Includes usage examples for envFrom and individual env var injection.

Kubernetes ConfigMaps

ConfigMaps decouple configuration from container images — you change config without rebuilding.

Two Injection Methods

yaml
# Method 1: All keys as environment variables
envFrom:
  - configMapRef:
      name: my-app-config

# Method 2: Specific key as environment variable env:

  • name: LOG_LEVEL

valueFrom: configMapKeyRef: name: my-app-config key: LOG_LEVEL

# Method 3: Mount as a file volumes:

  • name: config

configMap: name: my-app-config volumeMounts:

  • name: config

mountPath: /etc/config ```

Update a ConfigMap

bash
kubectl edit configmap my-app-config -n default
# or
kubectl create configmap my-app-config --from-env-file=.env -o yaml --dry-run=client | kubectl apply -f -

Namespaced — not shared across namespaces

A ConfigMap in default is invisible to pods in production. Create per-namespace or use Helm with environment-specific values.

Frequently Asked Questions

When should I use a ConfigMap vs a Secret?

ConfigMaps are for non-sensitive configuration: feature flags, log levels, service URLs, port numbers. Secrets are for sensitive data: passwords, API keys, TLS certificates. ConfigMap data is stored as plain text in etcd. Secret data is base64-encoded (not encrypted by default — enable encryption at rest for production clusters).

Does updating a ConfigMap immediately update running Pods?

Not automatically. Pods using envFrom (environment variables) only see the new values on restart — the env vars are set at container start time. Pods using volume mounts (ConfigMap as a file) do get automatic updates — kubelet polls and updates the mounted files. If you need hot-reload, mount the ConfigMap as a volume and have your app watch the file for changes.

What is the size limit for a ConfigMap?

1 MiB per ConfigMap (Kubernetes limit). For larger configs (e.g. a big nginx.conf or application.properties), split into multiple ConfigMaps, or use a Secret if the data is sensitive. For very large configs, consider a ConfigMap backed by an external source via the External Secrets Operator.

Can I use ConfigMaps for multi-line values like config files?

Yes. Use YAML block scalar syntax: key: | followed by indented lines. This is the standard way to inject full config files (nginx.conf, prometheus.yml, etc.) via ConfigMaps. The generator uses the simple key=value format — for file injection, edit the generated YAML to use block scalars.

Related Guides