Some settings are not yours to type. The Pod's name, its namespace, the node it landed on: the cluster decides those after you apply the manifest. The downward API hands them to the container.
fieldRef
yaml
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: MY_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: MY_NODE
valueFrom:
fieldRef:
fieldPath: spec.nodeNameThe paths are the Pod's own fields, the ones you read with -o yaml. Inside the container:
text
learner@shallows:~$ kubectl exec market-api -- env | grep MY_
MY_POD_NAME=market-api
MY_NAMESPACE=caverns
MY_POD_IP=10.42.0.11
MY_NODE=shallows-node-1Pod objectmetadata.name, status.podIP, ...
fieldRef
container environmentMY_POD_NAME, MY_POD_IP, ...
resourceFieldRef
The same idea for the container's own resources (Chapter 6 teaches them): resourceFieldRef with resource: limits.memory tells a program how much memory it may use, so it can size its caches.
Why an app wants this
| Fact | Used for |
|---|---|
| Pod name | Log lines and metrics that say which replica spoke |
| Namespace | Building the full DNS name of a sibling Service |
| Pod IP | Registering itself with a peer |
| Node name | Debugging, locality |