首页 > 其他分享 >downwardAPI

downwardAPI

时间:2023-05-27 12:11:06浏览次数:33  
标签:resource name downwardAPI cpu resourceFieldRef pod spec

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

标签:resource,name,downwardAPI,cpu,resourceFieldRef,pod,spec
From: https://www.cnblogs.com/wangend/p/17436540.html

相关文章

  • 33、K8S-配置管理之Secret、DownwardAPI
    1、secret1.1、基础知识1.1.1、Secret简介secretvolume为Pod提供加密的信息,相比于直接将敏感数据配置在Pod的定义或者镜像中,Secret提供了更加安全的机制,将共享的数据......
  • 从应用访问Pod元数据-DownwardApi的应用
    对于某些需要调度之后才能知道的数据,比如pod的ip,主机名,或者pod自身的名称等等,k8s依旧很贴心的提供了DownwardAPI的方式来获取此类数据,并且可以通过环境变量或者文......