Kubernetes
ConfigMap
Cluster Management
DevOps
Configuration Analysis

Figure out where ConfigMap values are used in the cluster

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Finding where ConfigMap values are used in a Kubernetes cluster is partly a manifest search problem and partly an application-behavior problem. Kubernetes can tell you which workloads reference a ConfigMap, but it cannot tell you whether the container actually reads every key after startup. You need to inspect both resource definitions and runtime usage patterns to get the full picture.

Start by Finding Direct ConfigMap References

Most ConfigMap usage appears in pod templates through three patterns: envFrom.configMapRef, env.valueFrom.configMapKeyRef, and volumes.configMap. Searching rendered workload specs is the fastest way to locate them.

bash
kubectl get deploy,statefulset,daemonset,job,cronjob -A -o yaml \
  | grep -n "configMapRef\|configMapKeyRef\|configMap:"

This gives you a broad first pass across common workload types. It is especially useful when the cluster is large and you do not yet know which namespace or controller owns a particular setting.

Query for One Specific ConfigMap

If you already know the ConfigMap name, narrow the search so you can see which workloads refer to it directly.

bash
1kubectl get deploy,statefulset,daemonset,job,cronjob -A -o json \
2  | jq -r '
3    .items[]
4    | select(
5        ([.spec.template.spec.volumes[]?.configMap.name]
6       + [.spec.template.spec.containers[]?.envFrom[]?.configMapRef.name]
7       + [.spec.template.spec.containers[]?.env[]?.valueFrom.configMapKeyRef.name]
8       + [.spec.template.spec.initContainers[]?.envFrom[]?.configMapRef.name]
9       + [.spec.template.spec.initContainers[]?.env[]?.valueFrom.configMapKeyRef.name])
10        | any(. == "app-config")
11      )
12    | "\(.kind) \(.metadata.namespace)/\(.metadata.name)"
13  '

Replace "app-config" with the name of the ConfigMap you are investigating. That command is often enough to build a dependable impact list before changing or deleting a ConfigMap.

Inspect How the Workload Consumes the Data

A reference tells you that the ConfigMap is available, but not how the application uses it. You still need to inspect the pod spec to understand the consumption pattern:

  • Environment variables expose keys as process environment entries.
  • Volume mounts expose keys as files on the container filesystem.
  • Command arguments may reference a mounted file path or environment variable.
bash
kubectl get deployment my-api -n prod -o yaml

When the ConfigMap is mounted as files, check the mount path and key names. A key called settings.yaml mounted under /app/config usually means the application reads /app/config/settings.yaml. If the workload uses envFrom, every key becomes an environment variable, which changes how you track downstream usage.

Check for Projected Volumes and Optional References

Some workloads use projected volumes that combine ConfigMaps, Secrets, and downward API data into a single mount. These do not show up when you search only for volumes.configMap.

bash
1kubectl get deploy -A -o json \
2  | jq -r '
3    .items[]
4    | .spec.template.spec.volumes[]?
5    | select(.projected != null)
6    | .projected.sources[]?
7    | select(.configMap != null)
8    | .configMap.name
9  '

Also watch for optional: true on ConfigMap references. When a ConfigMap is marked optional, the pod starts even if the ConfigMap does not exist. This means the reference is easy to miss because the workload is running without errors even though the ConfigMap may not be present.

yaml
1env:
2  - name: FEATURE_FLAG
3    valueFrom:
4      configMapKeyRef:
5        name: feature-flags
6        key: enable-beta
7        optional: true

Use kubectl to List ConfigMap Consumers

For a quick check, you can describe the ConfigMap and see if any events reference it, though this is limited. A more reliable approach is to check which pods currently have the ConfigMap mounted.

bash
1# List all pods that mount a specific ConfigMap as a volume
2kubectl get pods -A -o json \
3  | jq -r '
4    .items[]
5    | select(.spec.volumes[]?.configMap.name == "app-config")
6    | "\(.metadata.namespace)/\(.metadata.name)"
7  '

Remember That the Real Consumer Is the Application

Kubernetes only wires the data into the pod. The application decides whether it reads the value on startup, watches the mounted file for changes, or ignores a key entirely. That means manifest inspection finds references, but source code, logs, and runtime behavior tell you whether the value matters.

If you need certainty before making a change, combine the Kubernetes search with application-level verification:

  • Inspect the container command and arguments for references to config file paths.
  • Search the application source code or container image for env var reads and file reads.
  • Watch logs after changing a test key in a staging environment.
  • Check whether the application supports hot-reloading of mounted ConfigMap files (kubelet updates mounted files within 60 to 90 seconds by default).

That is the difference between "this ConfigMap is mounted here" and "this value actually drives behavior."

Common Pitfalls

  • Searching only running pods and missing the owning Deployment, StatefulSet, Job, or CronJob that recreates them. Always search the controller spec, not just pod specs.
  • Checking containers but forgetting initContainers, which often consume setup-related ConfigMaps for database migrations or certificate generation.
  • Looking only for the ConfigMap name and missing configMapKeyRef or envFrom usage patterns that reference individual keys.
  • Assuming a referenced key is actively used by the application without checking the mounted path or environment variable mapping in the source code.
  • Forgetting namespace boundaries and concluding that a similarly named ConfigMap in another namespace is the same dependency.
  • Overlooking projected volumes, which bundle ConfigMaps together with other sources and require a different jq query to find.
  • Deleting a ConfigMap that is marked optional: true without realizing the application silently falls back to a default value, which may change behavior in unexpected ways.

Summary

Search workload specs for configMapRef, configMapKeyRef, and volumes.configMap to find direct references. Narrow the search by ConfigMap name when you need an impact list for one object. Check projected volumes and optional references, which are easy to miss. Inspect the consuming pod spec to see whether values become env vars or mounted files. Remember that Kubernetes shows references, while the application determines actual usage. Combine manifest inspection with app-level verification before deleting or changing important ConfigMap data.


Course illustration
Course illustration

All Rights Reserved.