ConfigMaps

ConfigMaps provide a means of storing application configuration and injecting it into a pod. Data can be bound to a pod either via files or using environment variables.

apiVersion: v1
kind: ConfigMap
metadata:
    name: my-settings
data:
    db_user: app_prod
    db_host: db

Binding via environment variables

To use an individual value as an environment variable, define it using valueFrom: configMapKeyRef:

# Inside a Pod.spec.containers[*]
env:
  - name: DB_USER
      valueFrom:
          configMapKeyRef:
              name: my-settings
              key: db_user

Alternatively, consume all of the keys as environment variables:

# Inside a Pod.spec.containers[*]
envFrom:
  - configMapRef:
      name: my-settings

Note that, since environment variables are exported at pod startup time and can't be changed, changes to these values won't be effective until the pod is replaced.

Binding via volumes

When using a volume, each key will become its own file under the specified mountPath:

# Inside a Pod.spec
volumes:
  - name: config
      configMap:
          name: my-settings
containers:
    app:
        volumeMounts:
          - name: config
              mountPath: /etc/my-app

In this configuration, changes to the configuration values would be immediately reflected in the volume.


Children
  1. Extract files with jq

Backlinks