liveBook · Manning

Configmap

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A ConfigMap is a Kubernetes API object that stores non-confidential configuration data for use by workloads or cluster components.

A ConfigMap stores non-confidential configuration data separately from a workload. A pod can receive its data through environment variables or a volume mounted in a container. Use a Secret instead when the data is sensitive. section 4.2.4 section 4.3

To create and use one:

  • Generate a YAML starting point: `kubectl create cm redis-config --from-literal=key1=config1 --from-literal=key2=config2 --dry-run=client -o yaml > redis-config.yaml`. The dry run writes a manifest without creating the object. section 4.2.4
  • Edit the `data` entries as needed; use `|` for a multiline value such as Redis configuration. Create or update the object with `kubectl apply -f redis-config.yaml`. section 4.2.4
  • Reference the ConfigMap from the pod as a mounted volume or through environment variables. For the Redis volume example, check the volume and mount configuration, then inspect the configuration through Redis CLI. section 4.2.4

ConfigMaps also hold cluster-component configuration. In `kube-system`, separate ConfigMaps contain kubelet and CoreDNS settings; inspect them with `kubectl -n kube-system get cm`. After changing the kubelet ConfigMap for a new cluster DNS Service address, run the node's kubelet-configuration upgrade step and verify the address in a newly created pod. section 6.2.2 section 6.1

Verify a kubelet DNS change

Edit the configuration with `kubectl -n kube-system edit cm kubelet-config`, then run `kubeadm upgrade node phase kubelet-config`. Create a new pod and inspect its `/etc/resolv.conf`; in the illustrated Service-range change, its nameserver is `100.96.0.10`. Test name resolution from that pod as well. section 6.1

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through manifest generation, pod injection, and verification, then applies an edit-and-upgrade workflow to kubelet DNS configuration.
Examples
Uses a Redis configuration volume and a kubelet DNS-address change checked from a new pod.
What it assumes
Assumes familiarity with pods, kubectl, and YAML while demonstrating how to generate and apply a ConfigMap manifest.
What you can do after
Operate/configure it by creating and mounting a ConfigMap, or editing kubelet configuration and verifying a new pod's DNS settings.
How it connects
Connects pods, volumes, environment variables, Secrets, kubelet, and CoreDNS.

Also explained in

Compare how 8 books explain configmap →

Related concepts

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