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

5/28/2019

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, e.g. when cluster resources are exhausted, or our app is not allowed to auto-scale (further).

-- HannesM
kubernetes
kubernetes-pod
resource-utilization
resources

1 Answer

5/29/2019

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
-- Alassane Ndiaye
Source: StackOverflow