⌂ Home

ConfigMap as a Volume

Mount ConfigMap keys as files so applications can read runtime configuration from the filesystem.

A ConfigMap volume turns each key into a file and each value into file content. This fits applications that expect configuration files instead of environment variables.

Core Concepts

Filesystem projection

Keys become files inside a mounted directory such as /etc/config.

Externalized settings

The image stays the same while the runtime configuration changes per environment.

Config, not secrets

Use ConfigMaps for non-sensitive data and Secrets for passwords, tokens, and certificates.

ConfigMap Volume Flow

1

Create the ConfigMap

Store settings as named keys in a ConfigMap resource.

2

Mount it as a volume

The Deployment or Pod references the ConfigMap in the volumes section.

3

Expose files in the container

Kubernetes projects the ConfigMap into a mount path as regular files.

4

Application reads files

The process loads its configuration from the mounted path rather than from baked-in defaults.

Key point: ConfigMap volumes feel most natural when the app already knows how to consume config files.

Representative YAML

ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  database_url: jdbc:mysql://localhost:3306/mydb
  log_level: info

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: configmap-deployment
spec:
  template:
    spec:
      containers:
      - name: app
        image: nginx
        volumeMounts:
        - name: config-volume
          mountPath: /etc/config
      volumes:
      - name: config-volume
        configMap:
          name: app-config

Config Consumption Choices

PatternHow Data AppearsBest Fit
Environment variablesProcess environment entriesSimple startup settings
ConfigMap volumeFiles in a mounted directoryApps expecting config files or templates
Secret volumeSensitive files in a mounted directoryCredentials and keys
Design hint: If the app reads a config file already, do not force everything through environment variables.

How To Use It In Practice

Web server config

Project NGINX or Apache config snippets without rebuilding the image.

Environment-specific settings

Mount different data for dev, test, and prod while keeping the same container image.

Runtime inspection

Mounted files make it easy to confirm what configuration the container can actually see.