简体   繁体   English

Kubernetes中的容器能否确定其自身的资源利用率和限制?

[英]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? 我的容器化应用如何确定自己当前的资源利用率以及Kubernetes分配的最大限制? Is there an API to get this info from cAdvisor and/or Kubelet? 是否有API可从cAdvisor和/或Kubelet获取此信息?

For example, my container is allowed to use maximum 1 core, and it's currently consuming 800 millicores. 例如,我的容器最多只能使用1个核心,目前消耗800毫安。 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. 您可以使用Kubernetes Downward Api来获取限制和请求。 The syntax is: 语法为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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