liveBook · Manning

Environment variable

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

An environment variable is a named value made available to a process through its execution environment.

An environment variable is a named value made available to a process through its execution environment. In Kubernetes, it passes application configuration or sensitive values into a container. section 4.2.5 section 4.2.4

Use environment variables to:

  • Inject ConfigMap values such as application settings, log levels, or web-application configuration. section 4.2.4
  • Inject Secret values through valueFrom and secretKeyRef rather than placing the value directly in the pod definition. section 4.2.5
  • Repair a failing Deployment by identifying the required variable in container logs and adding it with kubectl edit or kubectl set env. section 8.1

Reference a Secret from a pod

Define a container variable with valueFrom.secretKeyRef, for example: env: - name: DEV_PASS valueFrom: secretKeyRef: name: dev-login key: username. After applying the manifest, verify the value with kubectl exec secret-env -- printenv DEV_USER DEV_PASS. section 4.2.5

Diagnose a missing database variable

When a MySQL pod enters CrashLoopBackOff, run kubectl logs to find the required password variable, then update the Deployment and confirm recovery with kubectl get po. section 8.1

Figure 4.22 You can pass the Secret data to a pod via environment variables. Set the command inside the container to print the environment variables (printenv). Don’t forget to change the c to -c.”
figure

Shows a pod receiving Secret data through environment variables and printing the resulting values. section 4.2.5

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

How deep it goes
Explains environment-variable references through YAML and kubectl edits, but does not descend into process-environment internals.
Examples
Uses ConfigMap settings, Secret references, a MySQL password, kubectl commands, YAML manifests, and printenv verification.
What you can do after
Operate/configure Kubernetes containers with ConfigMap or Secret values and diagnose missing variables using logs and kubectl.
How it connects
Connects environment variables with ConfigMaps, Secrets, Pods, Deployments, container logs, and CrashLoopBackOff.

Also explained in

Compare how 19 books explain environment variable →

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.