kubernetes /了解CPU资源限制 [英] kubernetes / understanding CPU resources limits

查看:126
本文介绍了kubernetes /了解CPU资源限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自多年来裸机上运行的节点/轨应用程序;我曾经能够在单台机器上运行尽可能多的应用程序(比如说,数字海洋上的2Go可以轻松处理10个应用程序,无需担心,基于正确的优化或相当低的通信量)



事情是,使用kubernetes,游戏听起来完全不同。我已经为2个标准vm(3.75Go)设置了一个入门集群。



使用以下命令为部署指定限制:

 资源:
请求:
cpu:64m
内存:128Mi
限制:
cpu:128m
内存:256Mi

然后见证以下内容:

 命名空间名称CPU请求CPU限制内存请求内存限制
--------- - --- ------------ ---------- --------------- ---------- ---
默认api 64m(6%)128m(12%)128Mi(3%)256Mi(6%)

这个6%是指什么?



试图降低CPU限制,像20Mi ...应用程序启动(显然, 没有足够的资源)。文档说它是CPU的百分比。那么,3.75Go机器的20%?那么这6%来自哪里呢?

然后将节点池的大小增加到n1-standard-2,同一个pod有效地跨越节点的3%。这听起来合乎逻辑,但它实际上指的是什么?



仍然怀疑这部分的计量指标是什么。



该应用程序在启动时似乎需要大量内存,但它只使用这个6%的一小部分。然后我觉得我误解了某些东西,或者误用了所有东西。

感谢任何有经验的提示/建议,以便更好地理解
Best

解决方案

6%的CPU意味着节点CPU时间的6%(CPU请求)为该容器保留CPU时间。所以它保证它总是能够达到这个数量的CPU时间。如果还剩下CPU时间,它仍然可以突发高达12%(CPU限制)。



这意味着如果限制非常低,您的应用程序将需要更多时间开始。因此,活力探测器可能会导致准备就绪之前,因为应用程序花了太长时间。要解决这个问题,您可能需要增加活性探测的 initialDelaySeconds timeoutSeconds






另请注意,资源请求和限制定义了您的pod分配的资源量,而不是实际使用量。




  • 资源请求是您的pod保证在节点上获取的内容。这意味着所请求资源的总和不得高于该节点上的CPU /内存总量。

  • 资源限制是您的pod允许的上限使用。这意味着这些资源的总和可以高于实际可用的CPU /内存。


    因此,百分比告诉你多少CPU并记住您的pod分配的资源总数。 链接到文档: https://kubernetes.io/docs/user-guide/compute-resources/



    其他值得注意的是:




    • 如果您的pod使用的内存超过了限制内存中的内存量,则会获得OOMKilled(内存不足)。

    • 如果您的pod使用的内存多于请求中定义的内存,并且该节点运行我们的内存,则该Pod可能会获得OOMKilled,以确保其他Pod可以存活, li>
    • 如果您的应用程序需要比请求更多的CPU,它可以突破最大限度。 你的pod永远不会被杀死,因为它使用了太多的CPU。 / li>

    Coming from numerous years of running node/rails apps on bare metal; i was used to be able to run as many apps as i wanted on a single machine (let's say, a 2Go at digital ocean could easily handle 10 apps without worrying, based on correct optimizations or fairly low amount of traffic)

    Thing is, using kubernetes, the game sounds quite different. I've setup a "getting started" cluster with 2 standard vm (3.75Go).

    Assigned a limit on a deployment with the following :

            resources:
              requests:
                cpu: "64m"
                memory: "128Mi"
              limits:
                cpu: "128m"
                memory: "256Mi"
    

    Then witnessing the following :

    Namespace       Name            CPU Requests    CPU Limits  Memory Requests Memory Limits
    ---------       ----            ------------    ----------  --------------- -------------
    default         api             64m (6%)        128m (12%)  128Mi (3%)      256Mi (6%)
    

    What does this 6% refers to ?

    Tried to lower the CPU limit, to like, 20Mi… the app does to start (obviously, not enough resources). The docs says it is percentage of CPU. So, 20% of 3.75Go machine ? Then where this 6% comes from ?

    Then increased the size of the node-pool to the n1-standard-2, the same pod effectively span 3% of node. That sounds logical, but what does it actually refers to ?

    Still wonder what is the metrics to be taken in account for this part.

    The app seems to need a large amount of memory on startup, but then it use only a minimal fraction of this 6%. I then feel like I misunderstanding something, or misusing it all

    Thanks for any experienced tips/advices to have a better understanding Best

    解决方案

    The 6% of CPU means 6% (CPU requests) of the nodes CPU time is reserved for this pod. So it guaranteed that it always get at lease this amount of CPU time. It can still burst up to 12% (CPU limits), if there is still CPU time left.

    This means if the limit is very low, you application will take more time to start up. Therefore a liveness probe may kill the pod before it is ready, because the application took too long. To solve this you may have to increase the initialDelaySeconds or the timeoutSeconds of the liveness probe.


    Also note that the resource requests and limits define how much resources you pod allocates, and not the actual usage.

    • The resource request is what your pod is guaranteed to get on a node. This means, that the sum of the requested resources must not be higher than the total amount of CPU/memory on that node.
    • The resource limit is the upper limit of what your pod is allowed to use. This means the sum of of these resources can be higher than the actual available CPU/memory.

    Therefore the percentages tell you how much CPU and memory of the total resources your pod allocates.

    Link to the docs: https://kubernetes.io/docs/user-guide/compute-resources/

    Some other notable things:

    • If your pod uses more memory than defined in the limit, it gets OOMKilled (out of memory).
    • If your pod uses more memory than defined in the requests and the node runs our of memory, the pod might get OOMKilled in order to guarantee other pods to survive, which use less than their requested memory.
    • If your application needs more CPU than requested it can burst up to the limit.
    • You pod never gets killed, because it uses too much CPU.

    这篇关于kubernetes /了解CPU资源限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆