Config, storage and stateLesson 1 of 6
  1. ConfigMaps, not reconciled
    1. What belongs in a ConfigMap
    2. Consuming it
    3. Updates
    4. Rolling on change
    5. Optional references
    6. Generators
  2. Secrets and external secret stores, not reconciled
  3. Volumes inside a pod, not reconciled
  4. PersistentVolumes, claims and StorageClasses, not reconciled
  5. StatefulSets, not reconciled
  6. Snapshots, clones and volume attributes, not reconciled

ConfigMaps

A ConfigMap keeps non-secret settings out of the image. The kubelet hands them to containers as environment variables or files, and only a volume mounted at a directory follows an update.

  • 20 min
  • 4 objectives
  • 6 scenes
  • Includes an On AWS layer

Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.

An image that hardcodes its database host, log level and feature flags has to be rebuilt for every environment it runs in. Kubernetes splits that apart: the image carries the code, and a ConfigMapAn API object that holds non-secret configuration as key-value pairs, for pods to read as environment variables, command arguments or files. carries the settings. The same image then runs in staging and production with a different ConfigMap in each namespace.

This lesson follows a ConfigMap from the API server into a container, and then into the part people get wrong: what happens when it changes.

Reconcile, in 6 scenes

What belongs in a ConfigMap

A ConfigMap has two maps and nothing else of substance. data holds UTF-8 strings: short values such as LOG_LEVEL: info, or whole files such as an nginx.conf written as a multi-line string. binaryData holds base64-encoded bytes for content that is not UTF-8. A key may appear in only one of the two, and every key must be made of letters, digits, -, _ and ., because a key can become a file name.

Three limits shape what goes in:

  • Size. The data in one ConfigMap cannot exceed 1 MiB. Anything larger belongs in a volume, an image or an external service.
  • Secrecy. A ConfigMap provides no secrecy at all. Passwords, tokens and keys go in a Secret, which the next lesson covers. Like every other object, a ConfigMap is stored in etcd under /registry/configmaps/<namespace>/<name>, in the same keyspace as Secrets and Pods. Encryption at rest is an API server setting that can cover either kind, not a property of the object.
  • Scope. A ConfigMap lives in one namespace, and a pod can reference only ConfigMaps in its own namespace. Static pods, which the kubelet runs from files on the node, cannot reference ConfigMaps at all; from Kubernetes 1.37 the kubelet enforces that with no opt-out.

How you divide settings between ConfigMaps decides how changes spread. One ConfigMap per application and purpose (logging, feature flags, a server config file) keeps a change to one concern from touching pods that only read another. The same names in every namespace, with different values, let one manifest serve every environment: the pod spec says web-config, and the namespace decides which web-config it gets.

You can write a ConfigMap as YAML and keep it in version control, or create one from the command line. --from-literal adds a key per flag, --from-file turns a file into a key named after the file (--from-file=app.yaml=config.yaml renames it), and --from-env-file reads KEY=value lines.

Create a ConfigMap from literals
kubectl create configmap web-config --from-literal=LOG_LEVEL=info --from-literal=CACHE_TTL=30s
configmap/web-config created
kubectl get configmap web-config -o yaml
apiVersion: v1
data:
  CACHE_TTL: 30s
  LOG_LEVEL: info
kind: ConfigMap
metadata:
  creationTimestamp: "2026-11-19T09:00:50Z"
  name: web-config
  namespace: default
  resourceVersion: "252"
  uid: bfaad909-c0c3-4cfe-8fe2-aa4c4b47d0ab

Consuming it

A pod can take a ConfigMap in four ways: as environment variables, as command-line arguments built from those variables, as files in a volume, or by reading the object through the Kubernetes API. The first three are done by the kubeletThe node agent that starts a pod’s containers and sets up their environment and volumes. when it starts the container. Your application never talks to the API server and needs no permissions. The fourth needs RBAC get on configmaps, plus watch to follow changes, and in return the application sees each change as soon as its watch delivers it.

The kubelet fetches a ConfigMap only because a pod bound to its node references it. The API server’s Node authorizer enforces that: a kubelet may read ConfigMaps, Secrets, PersistentVolumeClaims and PersistentVolumes only when a pod bound to its node uses them. A reference in the pod spec is therefore the whole permission model for the first three paths. Whoever can create the pod can have its containers read any ConfigMap in the namespace.

Here is one ConfigMap holding two plain values and a whole nginx server block:

apiVersion: v1
kind: ConfigMap
metadata:
  name: web-config
data:
  LOG_LEVEL: info
  CACHE_TTL: 30s
  default.conf: |
    server {
      listen 8080;
      location / { return 200 "ok\n"; }
    }

And a pod that consumes it three ways at once:

apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  containers:
  - name: web
    image: nginx:1.31
    env:
    - name: LOG_LEVEL              # one key, under a name you choose
      valueFrom:
        configMapKeyRef:
          name: web-config
          key: LOG_LEVEL
    volumeMounts:
    - name: config                 # every key becomes a file in /etc/web
      mountPath: /etc/web
      readOnly: true
    - name: config                 # one key, placed as one file
      mountPath: /etc/nginx/conf.d/default.conf
      subPath: default.conf
      readOnly: true
  volumes:
  - name: config
    configMap:
      name: web-config
One ConfigMap, three ways in
kubectl apply -f web-config.yaml
configmap/web-config created
kubectl apply -f web.yaml
pod/web created
kubectl wait --for=condition=Ready pod/web
pod/web condition met
kubectl get pod web
NAME   READY   STATUS    RESTARTS   AGE
web    1/1     Running   0          15s
kubectl exec web -- printenv LOG_LEVEL
info
kubectl exec web -- ls /etc/web
CACHE_TTL
LOG_LEVEL
default.conf
kubectl exec web -- cat /etc/nginx/conf.d/default.conf
server {
  listen 8080;
  location / { return 200 "ok\n"; }
}

Single variables. env[].valueFrom.configMapKeyRef copies one key into one variable, and the variable’s name does not have to match the key. Variables you define can feed command and args with the $(LOG_LEVEL) syntax, which is how a ConfigMap value becomes a command-line flag.

Every key at once. envFrom with a configMapRef turns every key into a variable of the same name, and prefix: CFG_ namespaces them. When the same name comes from several places, an entry in env wins over anything from envFrom. An environment variable name may be any printable ASCII character except =, a rule on by default from Kubernetes 1.32 and locked on from 1.34, so every legal ConfigMap key is also a legal variable name. Material written for 1.31 and earlier says envFrom skips keys such as 1badkey and records an InvalidEnvironmentVariableNames event; that happens only on those versions, or where the RelaxedEnvironmentVariableValidation feature gate is turned off on 1.32 or 1.33.

Files. A configMap volume writes each key as a file named after the key, with mode 0644 unless defaultMode says otherwise. items selects which keys appear and renames them:

volumes:
- name: config
  configMap:
    name: web-config
    items:
    - key: default.conf
      path: nginx/default.conf

Updates

Edit a ConfigMap that pods are using and three different things happen, depending on how each container consumes it.

ConsumerSees the new value
env or envFromNever. The kubelet resolves variables once, when it creates the container.
Volume mounted at a directoryYes, after the kubelet’s next sync of the pod and its cache catching up.
Single file mounted with subPathNever.
The application reading the APIWhen its watch delivers the change.

The volume case is worth understanding in detail. The kubelet does not edit files in place. It writes the new keys into a fresh hidden directory, then atomically repoints a ..data symlink at it. Each visible file is itself a symlink through ..data, so a reader sees either the old set of files or the new set, never half of each.

The timing is the kubelet sync period plus the delay of the kubelet’s cache. The sync period is 1 minute by default. The cache follows configMapAndSecretChangeDetectionStrategy in the kubelet configuration, which is Watch by default, so the cache delay is the watch delay. Expect roughly a minute, not an instant, and do not build anything on a fixed upper bound.

Getting new bytes into the file is half the job. The application has to notice. Some programs re-read their configuration on a signal or on a schedule, some watch the directory with inotify (watch the directory, because the files are replaced rather than written), and many read configuration once at startup and never again. For those, a mounted update changes nothing until the pod restarts.

Rolling on change

A Deployment rolls out when its pod template changes. Editing a ConfigMap changes a different object, so the template stays the same and no new pods are created. Three techniques turn a configuration change into a template change.

Restart by hand. kubectl rollout restart deployment/web writes a kubectl.kubernetes.io/restartedAt annotation into the template, which rolls every pod. It works, but nothing records which configuration each revision ran with.

A checksum annotation. Templating tools can hash the rendered ConfigMap into an annotation on the pod template. The Helm convention looks like this in a chart’s Deployment template:

spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}

When the ConfigMap’s content changes, the hash changes, the template changes, and the Deployment rolls with its usual surge and readiness checks. The ConfigMap itself is still edited in place, so a pod that restarts for any other reason during the rollout picks up the new values too.

Immutable, versioned ConfigMaps. Give each version its own name, web-config-v1, web-config-v2, and set immutable: true. The Deployment references a specific version. Shipping a change means creating the next version and changing the name in the template. That is a template change, so the rollout happens with surge and readiness checks, and the previous ReplicaSet still references the previous version, so kubectl rollout undo returns to exactly the configuration that worked. Delete old versions once no ReplicaSet you might roll back to references them.

Manifestweb-config-v1.yaml

Edit web-config-v1.yaml, then apply it to this page's cluster
In the cluster
  • configmap/web-config-v1
Tab indents two spaces and Shift+Tab outdents. To leave the editor, press Escape, then Tab. Control+Enter or Command+Enter to apply.
The preview runs once this page's cluster starts.

Change LOG_LEVEL and apply: the API server refuses the edit. Delete the immutable line and apply: it refuses that too, because immutable cannot be switched back.

Immutability, GA since Kubernetes 1.21, does two things. It protects the object: the API server rejects changes to data and binaryData, and immutable itself cannot be switched back to false. The only way out is to delete and recreate the object. It also reduces load: the kubelet closes its watch on any ConfigMap marked immutable, which matters in clusters with tens of thousands of ConfigMap mounts.

An immutable ConfigMap refuses edits
kubectl patch configmap web-config-v1 --type merge -p '{"data":{"LOG_LEVEL":"debug"}}'
The ConfigMap "web-config-v1" is invalid: data: Forbidden: field is immutable when `immutable` is set

Controllers such as Stakater Reloader take a fourth approach: they watch ConfigMaps and trigger a restart of the workloads that reference them. That automates the hand restart, with the same lack of history.

Optional references

A missing ConfigMap does not stop a pod from being created. The API server accepts it and the scheduler places it on a node. What fails is the container start on that node, and how it fails depends on the reference:

  • A missing ConfigMap or key behind env or envFrom leaves the container in CreateContainerConfigError. The event names the key and the ConfigMap.
  • A missing ConfigMap behind a volume stops the pod earlier. The kubelet cannot set up the volume, so the pod stays in ContainerCreating with no IP address, and FailedMount events name the ConfigMap.
Two pods waiting on configuration
kubectl get pods
NAME       READY   STATUS                       RESTARTS   AGE
env-demo   0/1     CreateContainerConfigError   0          20s
vol-demo   0/1     ContainerCreating            0          20s
kubectl get events --field-selector reason=Failed
LAST SEEN   TYPE      REASON   OBJECT         MESSAGE
7s          Warning   Failed   pod/env-demo   Error: couldn't find key CACHE_TTL in ConfigMap default/app-config
kubectl get events --field-selector reason=FailedMount
LAST SEEN   TYPE      REASON        OBJECT         MESSAGE
4s          Warning   FailedMount   pod/vol-demo   MountVolume.SetUp failed for volume "flags" : configmap "feature-flags" not found

Neither pod has logs, because neither container ever ran. The events are the evidence. Check the ConfigMap’s namespace first (it must match the pod’s), then the spelling of the name and the key. The kubelet keeps retrying, so once the ConfigMap or key exists the pod starts on its own without being recreated.

Mark a reference optional: true when the container really can run without it:

env:
- name: FEATURE_FLAGS
  valueFrom:
    configMapKeyRef:
      name: feature-flags
      key: flags
      optional: true

With an optional reference a missing ConfigMap or key leaves the variable unset, an optional volume mounts as an empty directory, and a missing key’s file is simply absent. If an optional ConfigMap appears later, a mounted volume fills in on a later sync, while an environment variable stays unset until the container restarts. Use optional deliberately: a container that starts without its configuration and runs on defaults is often harder to notice than one that refuses to start.

Generators

Kustomize, built into kubectl as kubectl kustomize and kubectl apply -k, can generate ConfigMaps from literals and files:

# kustomization.yaml
resources:
- deployment.yaml
configMapGenerator:
- name: web-config
  literals:
  - LOG_LEVEL=info
  files:
  - default.conf

The generator appends a hash of the content to the name, producing something like web-config-<hash>, and rewrites every reference to web-config in the other resources to the generated name. Change a literal and both the name and the Deployment’s pod template change, so the next kubectl apply -k rolls the pods. It is the versioned-ConfigMap pattern without the manual bookkeeping. Two consequences follow. Old generated ConfigMaps accumulate until something prunes them, and generatorOptions: {disableNameSuffixHash: true} turns the suffix off, which also turns off the automatic rollout.

Watch an environment variable ignore an update

  1. kubectl --context kind-kx create configmap web-config --from-literal=LOG_LEVEL=info
  2. kubectl --context kind-kx create deployment cfg-demo --image=busybox:1.37 -- sleep 3600
  3. kubectl --context kind-kx set env deployment/cfg-demo --from=configmap/web-config
  4. kubectl --context kind-kx rollout status deployment/cfg-demo
  5. kubectl --context kind-kx exec deploy/cfg-demo -- printenv LOG_LEVEL
  6. kubectl --context kind-kx create configmap web-config --from-literal=LOG_LEVEL=debug --dry-run=client -o yaml | kubectl --context kind-kx apply -f -
  7. kubectl --context kind-kx exec deploy/cfg-demo -- printenv LOG_LEVEL
  8. kubectl --context kind-kx rollout restart deployment/cfg-demo
  9. kubectl --context kind-kx rollout status deployment/cfg-demo
  10. kubectl --context kind-kx exec deploy/cfg-demo -- printenv LOG_LEVEL
  11. kubectl --context kind-kx delete deployment cfg-demo
  12. kubectl --context kind-kx delete configmap web-config

For your own kind cluster kx: copy a command and paste it into your terminal. Run in the simulator runs the same command in this page's simulated cluster instead; nothing on this page touches your machine. The variable still reads info after the ConfigMap says debug. Only the pods created by the restart see debug.

Actual state

Check your understanding

5 checks

Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.

  1. Check 1 of 5

    A container sets CACHE_TTL from configMapKeyRef (ConfigMap web-config, key CACHE_TTL). The ConfigMap exists but has no such key, and the reference is not optional. What does kubectl get pod show?

  2. Check 2 of 5

    You edit a ConfigMap that a running pod consumes in three ways. Which one shows the new value without a restart?

  3. Check 3 of 5

    Check runs your command on a private cluster; what it prints shows here.

  4. Check 4 of 5

    app-config-v3 has immutable: true and you need a different LOG_LEVEL. What is the supported way to ship it?

  5. Check 5 of 5

    You change a value in the ConfigMap a Deployment reads through env. Why does nothing roll out?

Lesson not yet reconciled

Desired: 4 objectives, 0 metReconciled: 4 of 4 objectives met

  • Inject configuration as single environment variables, as whole ConfigMaps with envFrom, or as mounted files. (not yet met)
  • Predict which consumers of a ConfigMap see an update and which keep the old value until the pod restarts. (not yet met)
  • Roll pods on a configuration change with a checksum annotation or with immutable, versioned ConfigMaps. (not yet met)
  • Diagnose CreateContainerConfigError and FailedMount caused by a missing ConfigMap or key. (not yet met)

Pass every check above to reconcile this lesson.

Every check has passed, so the desired state is met. First-try accuracy: 0 of 5. This lesson's review cards are in your queue.

Practice

Put this lesson to work on the simulated cluster. Everything runs in your browser, with nothing to install.

Changed since the notes

This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.

Show 9 corrections
  1. Stale, true once, no longerConfigMaps and Secrets

    The notes said'EKS encrypts etcd at rest by default. You can enable envelope encryption with KMS for additional control.'

    CorrectedEKS applies envelope encryption to all Kubernetes API data (not only Secrets) by default on clusters running 1.28 or later, using KMS v2 and an AWS owned key; existing clusters were migrated by the eks:kms-storage-migrator role. Supplying a customer managed KMS key (or an existing Secrets-encryption key) makes that key the KEK for all API data. Every EKS-supported version (1.31 to 1.37) is covered, so 'you can enable envelope encryption' now means 'you can choose your own KMS key'.

    Sourcedocs.aws.amazon.com/eks/latest/userguide/envelope-encryption.html

  2. Stale, true once, no longerConfigMaps and Secrets

    The notes saidExternal Secrets Operator ExternalSecret resources

    CorrectedESO serves its resources at external-secrets.io/v1. v0.17.0 (2025-05-14) stopped serving v1beta1, so v1beta1 manifests fail with 'no matches for kind'. ESO reached v1.0.0 on 2025-11-07 and is on the 2.x line (v2.15.0 on 2026-11-10); v2.0.0 removed the Alibaba and Device42 providers. Lessons must use apiVersion external-secrets.io/v1.

    Sourcegithub.com/external-secrets/external-secrets/releases/tag/v0.17.0;%20https://github.com/external-secrets/external-secrets/releases/tag/v2.0.0

  3. Nuance, true with conditionsConfigMaps and Secrets

    The notes saidASCP via SecretProviderClass and CSI volume

    CorrectedASCP is available as the EKS add-on aws-secrets-store-csi-driver-provider (console, eksctl, API) in addition to Helm/manifests. The add-on itself needs no IAM permissions; pods need IRSA or EKS Pod Identity (both documented; AWS suggests AWSSecretsManagerClientReadOnlyAccess). Syncing mounted secrets into Kubernetes Secrets via SecretProviderClass secretObjects is a Secrets Store CSI Driver feature that requires the driver's secret sync to be enabled; whether the EKS add-on enables it by default was not confirmed.

    Sourcedocs.aws.amazon.com/eks/latest/userguide/workloads-add-ons-available-eks.html#add-ons-aws-secrets-store-csi-driver-provider;%20https://docs.aws.amazon.com/secretsmanager/latest/userguide/ascp-eks-installation.html

  4. Nuance, true with conditionsConfigMaps and Secrets

    The notes saidMounted ConfigMap updates take 'up to a minute by default'

    CorrectedThe documented delay is the kubelet sync period plus cache propagation delay. configMapAndSecretChangeDetectionStrategy defaults to Watch, so propagation is watch latency on top of the kubelet syncFrequency (default 1m): roughly a minute plus propagation, not a hard one-minute cap. Keys mounted with subPath never update, and env vars require a pod restart.

    Sourcekubernetes.io/docs/concepts/configuration/configmap#mounted-configmaps-are-updated-automatically

  5. Stale, true once, no longerConfigMaps and Secrets

    The notes saidenvFrom skips keys that are not valid environment variable names

    CorrectedRelaxedEnvironmentVariableValidation was beta and on by default in 1.32 to 1.33 and is GA (locked on) in 1.34: an env var name may be any printable ASCII character except '='. ConfigMap and Secret keys are limited to [-._a-zA-Z0-9]+, so on 1.32+ every key is a valid name and the skip (InvalidEnvironmentVariableNames event) only happens on 1.31 or with the gate disabled.

    Sourcekubernetes.io/docs/reference/command-line-tools-reference/feature-gates/;%20https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container

  6. Wrong, not trueConfigMaps and Secrets

    The notes saidSecret files have 'stricter default permissions' at mode 0644

    CorrectedBoth ConfigMap and Secret volumes default to defaultMode 0644, so nothing is stricter. The real difference is that the kubelet writes Secret volume data to tmpfs (memory) rather than node disk. Set defaultMode (for example 0400) to restrict access.

    Sourcekubernetes.io/docs/concepts/configuration/secret

  7. Nuance, true with conditionsConfigMaps and Secrets

    The notes saidImmutable Secrets help because 'the API server doesn't need to watch for changes'

    CorrectedThe benefit is right but the mechanism is misattributed: the kubelet closes its watches on ConfigMaps/Secrets marked immutable, which significantly reduces load on kube-apiserver in clusters with many mounts. The API server does not watch for changes itself.

    Sourcekubernetes.io/docs/concepts/configuration/configmap#configmap-immutable

  8. Wrong, not trueConfigMaps and Secrets

    The notes said'If a ConfigMap or Secret doesn't exist and isn't optional, pod creation fails'

    CorrectedThe Pod object is accepted and scheduled; it is the container that cannot start ('the Pod won't start'). Missing env/envFrom references give CreateContainerConfigError; missing volume sources leave the pod in ContainerCreating with FailedMount events. Missing keys behave the same unless marked optional.

    Sourcekubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap#restrictions

  9. Wrong, not trueConfigMaps and Secrets

    The notes said'In etcd, Secrets are stored separately from other resources'

    CorrectedSecrets live in the same etcd keyspace as every other resource, under /registry/secrets/<namespace>/<name>. Only an EncryptionConfiguration (resources: secrets) treats them differently, by encrypting them at rest; on EKS 1.28+ all API data is envelope-encrypted by default.

    Sourcekubernetes.io/docs/tasks/administer-cluster/encrypt-data

Every correction across the guide, by note and topic.

Sources

Checked against kubernetes.io and AWS documentation for Kubernetes 1.37 on .

  1. kubernetes.io/docs/concepts/configuration/configmap
  2. kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap
  3. kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container
  4. kubernetes.io/docs/reference/storage/volume-types#configmap
  5. kubernetes.io/docs/concepts/storage/volumes#using-subpath
  6. kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization
  7. kubernetes.io/docs/tasks/administer-cluster/encrypt-data
  8. kubernetes.io/docs/reference/access-authn-authz/node
  9. docs.aws.amazon.com/eks/latest/userguide/envelope-encryption.html
  10. docs.aws.amazon.com/eks/latest/userguide/workloads-add-ons-available-eks.html

ConfigMaps

↓ ↑ step, 1 to 6 scene, Esc leave

kind cluster kxLast command: Nothing run yet