简体   繁体   English

Kubernetes-CPU限制指示少于可用CPU

[英]Kubernetes - Indication of CPU limit less than available CPU

Objective 目的

Clarify the behaviour of K8S container cpu usage when limit is set far below available CPU, and confirm if the understanding how to set limit is correct. 澄清将限制设置为远远低于可用CPU时,K8S容器cpu使用情况的行为,并确认了解如何设置限制是正确的。

Background 背景

I have a node of 2CPU, hence 2000m can be the upper limit. 我有一个2CPU的节点,因此2000m可以是上限。 Every namespace is set with the LimitRange which limits CPU to 500m for container. 每个命名空间都设置有LimitRange,将容器的CPU限制为500m。

kind: LimitRange
metadata:
  name: core-resource-limits
    spec:
      limits:
      - default:
          cpu: 500m
          memory: 2Gi
        defaultRequest:
          cpu: 100m
        type: Container

Indication 迹象

Even when 2 CPU are available (no other process/container waiting) and a container is runnable, it can only use 0.5 CPU, and 1.5 CPU will be left unused. 即使有2个CPU可用(没有其他进程/容器等待)并且容器可运行,它也只能使用0.5个CPU,而1.5个CPU将不使用。 Is this correct? 这个对吗?

How to set LimitRange 如何设置LimitRange

I believe I can set the limit such as 75-80% of available 2 CPU to better utilise the CPU resource. 我相信我可以设置限制,例如可用2个CPU的75-80%,以更好地利用CPU资源。 Because in case there are multiple containers trying to claim CPU more than requests, K8S will allocate the CPU among containers based on the request value of each containers, as per the documentations (some from OpenShift but believe it is the same with K8S). 因为如果有多个容器试图索取更多的CPU资源,则根据文档(某些文件来自OpenShift,但相信与K8S相同),K8S将根据每个容器的请求值在各个容器之间分配CPU。 Is this correct? 这个对吗?

kind: LimitRange
metadata:
  name: core-resource-limits
    spec:
      limits:
      - default:
          cpu: 1500m
          memory: 2Gi
        defaultRequest:
          cpu: 100m
        type: Container

CPU Requests CPU请求

The CPU request represents a minimum amount of CPU that your container may consume, but if there is no contention for CPU, it can use all available CPU on the node. CPU请求代表您的容器可以消耗的最小CPU数量,但是如果没有CPU争用,它可以使用节点上所有可用的CPU。 If there is CPU contention on the node, CPU requests provide a relative weight across all containers on the system for how much CPU time the container may use. 如果节点上存在CPU争用,则CPU请求会在系统上所有容器提供一个相对权重,以表示该容器可以使用多少CPU时间。

CPU Limits CPU限制

Each container in a pod can specify the amount of CPU it is limited to use on a node. 容器中的每个容器都可以指定它在节点上限制使用的CPU数量。 CPU limits control the maximum amount of CPU that your container may use independent of contention on the node . CPU限制控制容器可以使用的最大CPU数量,而与节点上的争用无关 If a container attempts to exceed the specified limit, the system will throttle the container. 如果容器尝试超过指定的限制,则系统将对容器进行节流。 This allows the container to have a consistent level of service independent of the number of pods scheduled to the node. 这允许容器具有一致的服务级别,而与调度到节点的Pod数量无关。

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

The 6% of CPU means 6% (CPU requests) of the nodes CPU time is reserved for this pod. CPU的6%表示节点的6%(CPU请求)为该Pod预留了CPU时间。 So it guaranteed that it always get at lease this amount of CPU time. 因此,它保证了它总是能获得如此多的CPU时间。 It can still burst up to 12% (CPU limits), if there is still CPU time left . 如果仍然有剩余的CPU时间,它仍然可以爆裂高达12%(CPU限制)

How are Kubernetes CPU limits enforced? Kubernetes CPU限制如何执行?

Checking one of my containers, I see that Kubernetes set CpuPeriod, CpuQuota for them. 检查我的一个容器,我看到Kubernetes为它们设置了CpuPeriod和CpuQuota。 The Docker docs ( https://docs.docker.com/engine/reference/run/ ) mention the CFS documentation ( https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt ), and from the information there, it seems that these are hard limits Docker文档( https://docs.docker.com/engine/reference/run/ )提到了CFS文档( https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt ),并且从那里的信息看来,这些都是硬性限制

Kubernetes in Action 1st Edition by Marko Luksa Marko Luksa的Kubernetes in Action第一版

14.1.3. 14.1.3。 Understanding how CPU requests affect CPU time sharing 了解CPU请求如何影响CPU时间共享

But if one container wants to use up as much CPU as it can , while the other one is sitting idle at a given moment, the first container will be allowed to use the whole CPU time (minus the small amount of time used by the second container, if any). 但是, 如果一个容器要消耗尽可能多的CPU ,而另一个容器在给定时刻处于空闲状态,则第一个容器将被允许使用整个CPU时间(减去第二个容器所用的少量时间)容器(如果有))。 After all, it makes sense to use all the available CPU if no one else is using it , right? 毕竟,如果没有其他人使用它那么使用所有可用的CPU是有意义的 ,对吧? As soon as the second container needs CPU time, it will get it and the first container will be throttled back. 一旦第二个容器需要CPU时间,它将立即获取它,并且第一个容器将被限制。

在此处输入图片说明


Even when 2 CPU are available (no other process/container waiting) and a container is runnable, it can only use 0.5 CPU, and 1.5 CPU will be left unused. 即使有2个CPU可用(没有其他进程/容器等待)并且容器可运行,它也只能使用0.5个CPU,而1.5个CPU将不使用。 Is this correct? 这个对吗?

So this is correct. 所以这是正确的。

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

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