简体   繁体   中英

Can a container in Kubernetes determine its own resource utilization and limits?

How can my containerized app determine its own current resource utilization, as well as the maximum limit allocated by Kubernetes? Is there an API to get this info from cAdvisor and/or Kubelet?

For example, my container is allowed to use maximum 1 core, and it's currently consuming 800 millicores. In this situation, I want to drop/reject all incoming requests that are marked as "low priority".

-How can I see my resource utilization & limit from within my container?

Note that this assumes auto-scaling is not available, eg when cluster resources are exhausted, or our app is not allowed to auto-scale (further).

You can use the Kubernetes Downward Api to fetch the limits and requests. The syntax is:

volumes:
    - name: podinfo
      downwardAPI:
        items:
          - path: "cpu_limit"
            resourceFieldRef:
              containerName: client-container
              resource: limits.cpu
              divisor: 1m

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM