liveBook · Manning

Configmap

As explained in Kubernetes in Action, Second Edition

A ConfigMap is a Kubernetes API resource that stores non-confidential configuration data for use by pods or other workloads.

A ConfigMap is a Kubernetes API object that holds configuration as key–value pairs. A value can be a short string or a larger block of text, such as a configuration file. Keeping these values outside the pod manifest lets you reuse the same pod definition in development, staging, and production. section 8.2.1 section 8.2

A pod references a ConfigMap by name and can use selected entries. Multiple pods can share one ConfigMap, and a pod can reference more than one. Applications usually receive the values as environment variables or files rather than reading the Kubernetes API themselves. Small, single-line values suit environment variables; long or multiline values suit files. section 8.2.1 section 9.5.1

Create a ConfigMap

Run `kubectl create configmap kiada-config --from-literal status-message="Ready to start"` to create an entry named `status-message`. For a manifest instead, use `apiVersion: v1`, `kind: ConfigMap`, `metadata.name: kiada-config`, and `data.status-message: Ready to start`, then apply it with `kubectl apply`. You can also create entries from files or an environment file. Inspect the result with `kubectl get cm kiada-config -o yaml`. section 8.2.2

For file-based configuration, define a `configMap` volume in the pod and mount it in a container. Each included entry becomes a file the process can read. A pod can also select particular entries and set their paths. If a required ConfigMap for a volume is missing, none of the pod’s containers can start because volumes must be set up first. section 9.5.1

Listing 9.10 Defining a configMap volume in a pod
apiVersion: v1
kind: Pod
metadata:
  name: kiada-ssl
spec:
  volumes:
  - name: envoy-config            #1
    configMap:                    #1
      name: kiada-ssl-config      #1
  ...
  containers:
  ...
  - name: envoy
    image: luksa/kiada-ssl-proxy:0.1
    volumeMounts:                       #2
    - name: envoy-config                #2
      mountPath: /etc/envoy             #2
  ...

The pod manifest connects a named ConfigMap to a volume and mounts that volume at `/etc/envoy` in the container. section 9.5.1

Use a ConfigMap for ordinary configuration, such as a proxy configuration file. Use a Secret for sensitive values such as certificates and private keys. Separating these files from a container image also lets you update them without rebuilding the image. section 9.5 section 8.5

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains key–value storage, creation, environment-variable delivery, and configMap volumes, including missing-volume startup behavior.
Examples
Uses a status-message entry, kubectl creation commands, a YAML manifest, and a proxy configuration file mounted as a volume.
What it assumes
Builds on running an application in a pod and defining configuration in a pod manifest; defines the ConfigMap object explicitly.
What you can do after
Apply it via kubectl and pod manifests to supply configuration through environment variables or mounted files.
How it connects
Connects ConfigMaps to pods, environment variables, command-line arguments, volumes, container images, and Secrets.

Also explained in

Compare how 8 books explain configmap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.