Kubernetes ConfigMap Builder

Generate a K8s ConfigMap YAML for storing non-sensitive configuration

Build a Kubernetes ConfigMap YAML with simple key-value pairs and multi-line file entries for mounting as volumes or env vars. Handles YAML quoting and block scalars automatically. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is a Kubernetes ConfigMap?

A ConfigMap is an API object that stores non-confidential configuration as key-value pairs. Pods consume it as environment variables, command-line arguments, or files mounted from a volume, keeping configuration separate from container images.

Build Kubernetes ConfigMaps without YAML mistakes

A ConfigMap decouples configuration from your container image so the same image can run in dev, staging, and production with different settings. This builder lets you assemble both simple environment-style key-value pairs and full multi-line config files, then emits a valid v1 ConfigMap manifest you can apply directly with kubectl.

How it works

ConfigMaps store all data under a data: map. Simple values become single-line YAML scalars, while a multi-line file (such as an nginx.conf or application.properties) must be written as a YAML block scalar so newlines are preserved. The builder uses the | block scalar indicator and indents every line, which is exactly how kubectl create configmap --from-file renders it.

Keys and values are quoted automatically when they could be misread by a YAML parser — for example a value of true, a number like 8080, or a string starting with a special character. This avoids the classic bug where enabled: true is parsed as a boolean instead of the string Kubernetes expects.

Two ways to consume a ConfigMap in a pod

As environment variables

Use envFrom to inject every key as an environment variable, or valueFrom to pull a specific key:

envFrom:
  - configMapRef:
      name: my-config

Or for a single key:

env:
  - name: LOG_LEVEL
    valueFrom:
      configMapKeyRef:
        name: my-config
        key: log.level

As mounted files (volume)

Mount the ConfigMap as a directory, where each key becomes a filename and its value becomes the file’s content:

volumes:
  - name: config-volume
    configMap:
      name: my-config
containers:
  - volumeMounts:
      - name: config-volume
        mountPath: /etc/myapp/config

This pattern is ideal for multi-line config files like nginx.conf, application.yaml, or .env files that your application reads from disk.

YAML quoting rules that catch teams out

The builder quotes values that YAML would otherwise misinterpret:

Value typeExampleWithout quotesWith quotes
Boolean-like"true"Parsed as bool trueString “true”
Numeric"8080"Parsed as integer 8080String “8080”
Starts with {"{'key': 1}"Parsed as YAML mapKept as string
Contains :"host:port"May confuse parserSafe

Kubernetes mostly handles these gracefully when reading from etcd, but misconfigured YAML can produce silent errors in some controllers.

Tips and notes

  • Keys consumed as environment variables must be valid env-var names (letters, digits, underscores). File-style keys may contain dots, like app.properties.
  • To load every key as an env var, use envFrom with a configMapRef instead of listing each valueFrom individually.
  • Set immutable: true for config that never changes after deployment — it improves cluster performance and prevents accidental edits.
  • ConfigMaps are namespaced, so the name only needs to be unique within its namespace.
  • Never store secrets (passwords, tokens, API keys) in a ConfigMap — use a Secret object instead, which is base64-encoded and can be encrypted at rest.