downwardAPI
把pod和containers 的信息挂载到容器中
通过变量传递
fieldRef
可用字段 | 注释 | |
---|---|---|
node级别 | spec.nodeName |
|
status.hostIP |
||
pod级别 | metadata.namespace |
|
metadata.name |
||
status.podIP |
||
spec.serviceAccountName |
||
metadata.uid |
||
metadata.labels['app'] |
获取app标签的值 | |
metadata.annotations['deployment.kubernetes.io/revisio'] |
样例:
# pod.spec.containers.env.valueFrom
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resourceFieldRef
- name: MY_POD_cpu_limit
valueFrom:
resourceFieldRef:
resource: limits.cpu
divisor: 1m #作为被除数,决定了显示的单位
- name: MY_POD_cpu_request
valueFrom:
resourceFieldRef:
resource: requests.cpu
divisor: 1m #作为被除数,决定了显示的单位
- name: MY_POD_mem_request
valueFrom:
resourceFieldRef:
resource: requests.memory
divisor: 1Mi #作为被除数,决定了显示的单位
- name: MY_POD_mem_limits
valueFrom:
resourceFieldRef:
resource: limits.memory
divisor: 1Mi #作为被除数,决定了显示的单位
通过卷挂载
# pod.spec.volumes.downwardAPI
valuems:
- name: pod_info
downwardAPI:
items:
fieldRef:
fieldPath: spec.nodeName
resourceFieldRef:
resource: limits.cpu
containerName: cpu_limit
功能是什么意思
volumes:
- downwardAPI:
defaultMode: 420
items:
- path: pod_name
fieldRef:
fieldPath: metadata.name
- path: pod_cpu_limit
resourceFieldRef:
containerName: cpu_limit
divisor: "0"
resource: requests.cpu
name: podinfo
Information available via resourceFieldRef
:
A Container's hugepages limit (providing that the DownwardAPIHugePages feature gate is enabled)
A Container's hugepages request (providing that the DownwardAPIHugePages feature gate is enabled)
A Container's ephemeral-storage limit
A Container's ephemeral-storage request
这些属性只能在env 中引用
status.podIP
- the pod's IP address
spec.serviceAccountName
- the pod's service account name, available since v1.4.0-alpha.3
spec.nodeName
- the node's name, available since v1.4.0-alpha.3
status.hostIP
- the node's IP, available since v1.7.0-alpha.1