liveBook · Manning

Envfrom field

As explained in Kubernetes in Action, Second Edition

The envFrom field is a Kubernetes container specification field that imports key-value entries from a referenced configuration source as environment variables.

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

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains manifest structure, key naming, optional references, precedence, and Secret risks without covering filesystem projection implementation.
Examples
Demonstrates a Pod importing the kiada-config ConfigMap and inspecting resulting variables with kubectl exec.
What it assumes
Assumes familiarity with Pods and ConfigMaps while contrasting envFrom with individual env references.
What you can do after
Apply it via Kubernetes Pod manifests to bulk-load configuration and control optional references or source precedence.
How it connects
Connects envFrom with ConfigMap, Secret, environment variables, env, configMapRef, and secretRef.

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.