gpt4 book ai didi

docker - Kubernetes - CPU 限制小于可用 CPU 的指示

转载 作者:行者123 更新时间:2023-12-02 09:25:50 25 4
gpt4 key购买 nike

目标

澄清当限制设置远低于可用CPU时K8S容器CPU使用率的行为,并确认如何设置限制的理解是否正确。

背景

我有一个2CPU的节点,因此2000m可以是上限。每个命名空间都设置了 LimitRange,将容器的 CPU 限制为 500m。

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

指示

即使有 2 个 CPU 可用(没有其他进程/容器等待)并且容器可运行,它也只能使用 0.5 个 CPU,而 1.5 个 CPU 将未被使用。这是正确的吗?

如何设置LimitRange

我相信我可以设置限制,例如可用2个CPU的75-80%,以更好地利用CPU资源。因为如果有多个容器试图占用比请求更多的 CPU,K8S 将根据文档(一些来自 OpenShift,但相信与 K8S 相同)根据每个容器的请求值在容器之间分配 CPU。这是正确的吗?

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

CPU Requests

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. 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 Limits

Each container in a pod can specify the amount of CPU it is limited to use on a node. CPU limits control the maximum amount of CPU that your container may use independent of contention on the node. 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.

kubernetes / understanding CPU resources limits

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.

How are Kubernetes CPU limits enforced?

Checking one of my containers, I see that Kubernetes set CpuPeriod, CpuQuota for them. 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

最佳答案

Kubernetes in Action 1st Edition by Marko Luksa

14.1.3。了解 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). After all, it makes sense to use all the available CPU if no one else is using it, right? As soon as the second container needs CPU time, it will get it and the first container will be throttled back.

enter image description here

<小时/>

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. Is this correct?

所以这是正确的。

关于docker - Kubernetes - CPU 限制小于可用 CPU 的指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48725868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com