The envFrom field imports every key-value entry from a referenced ConfigMap into a container as an environment variable. It avoids repeating individual env entries when many values are needed. section 8.2.3
Import an entire ConfigMap
Use envFrom with configMapRef and specify the ConfigMap name. Setting optional to true lets the container start when the ConfigMap is absent; otherwise startup waits for it. section 8.2.3
Keep these operational distinctions in mind:
- Match keys to the environment variable names expected by the application; envFrom cannot transform keys, except by adding a prefix. section 8.2.3
- Provide multiple envFrom entries to combine ConfigMaps; when keys collide, the last ConfigMap takes precedence. section 8.2.3
- Use secretRef instead of configMapRef to import an entire Secret, but prefer Secret files because environment variables can leak through logs, reports, or child processes. section 8.3.3
Listing 8.11 Using envFrom to inject the entire ConfigMap into environment variables
kind: Pod
...
spec:
containers:
- name: kiada
envFrom: #1
- configMapRef: #2
name: kiada-config #2
optional: true #3
Inspect the complete Pod fragment showing envFrom, configMapRef, the referenced ConfigMap, and optional behavior. section 8.2.3
