Hands-on Lab·Certified Kubernetes Administrator
The Downward API
Inject a Pod's own name, node and IP as environment variables, mount its labels as files, then find that a 50m CPU request arrives as the number 1 and that the files update while the variables never do.
Configuration and Secrets Guide 38 of 103 Intermediate
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 30 min
The divisor default is the trap in this guide: resource values round up to whole units unless you say otherwise.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when a container needs to know something about its own Pod - its name, its node, its address, its labels. This matters because none of that is discoverable from inside the container, and the two ways of injecting it behave differently once the value changes.
- injecting Pod name, node and IP as environment variables a container cannot otherwise learn
- mounting the same information as files through a downwardAPI volume
- relabelling the Pod and watching the file update while the environment variable does not
- meeting the divisor default, where resource values round up to whole units
Before you start
- The ConfigMaps and Secrets guide, for how environment variables and volumes are injected.
- The requests, limits and QoS guide, since two of the values injected here are resource figures.
- A scratch namespace.
-
Six values a container cannot otherwise know
-
The same information as files
-
Files update, variables do not