简体   繁体   English

Kubernetes 请求真的有保障吗?

[英]Are Kubernetes requests really guaranteed?

I'm running a pod on an EKS node with 2500m of requests and no limits - it happily uses around 3000m typically.我正在 EKS 节点上运行一个 pod,请求数为 2500m,没有限制——它通常很乐意使用大约 3000m。 I wanted to test whether requests were really guaranteed, so I am running a CPU stress test pod on the same node, with 3000m requests and no limits again.我想测试请求是否真的有保证,所以我在同一个节点上运行了一个 CPU 压力测试 pod,有 3000m 的请求,并且再次没有限制。

This caused the original pod to not be able to use more than ~1500m of CPU - well below it's requests.这导致原始 pod 无法使用超过约 1500 米的 CPU - 远低于它的请求。 Then when I turned off the stress pod, it returned to using 3000m.然后当我关闭压力舱时,它又恢复使用 3000m。

There are a number of Kubernetes webpages which say that requests are what the pod is "guaranteed" - but does this only mean guaranteed for scheduling, or should it actually be a guarantee.有许多 Kubernetes 网页说请求是 pod 的“保证”——但这是否仅意味着保证调度,或者它实际上应该是一种保证。 If it is guaranteed, why might my pod CPU usage have been restricted (noting that there is no throttling for pods without limits).如果可以保证,为什么我的 pod CPU 使用率会受到限制(注意 pod 没有无限制的节流)。

Requests are not a guarantee that resources (especially CPU) will be available at runtime.请求并不能保证资源(尤其是 CPU)在运行时可用。 If you set requests and limits very close together you have better expectations, but you need every pod in the system to cooperate to have a real guarantee.如果您将请求和限制设置得非常接近,您会有更好的期望,但是您需要系统中的每个 Pod 进行合作才能有真正的保证。

Resource requests only affect the initial scheduling of the pod.资源请求只影响 Pod 的初始调度。 In your example, you have one pod that requests 2.5 CPU and a second pod that requests 3 CPU.在您的示例中,您有一个请求 2.5 CPU 的 Pod 和请求 3 CPU 的第二个 Pod。 If your node has 8 CPU, both can be scheduled on the same node, but if the node only has 4 CPU, they need to go on separate nodes (if you have the cluster autoscaler, it can create a new node).如果您的节点有 8 个 CPU,则两者可以调度在同一个节点上,但如果该节点只有 4 个 CPU,则它们需要在不同的节点上运行(如果您有集群自动缩放器,它可以创建一个新节点)。

To carry on with the example, let's say the pods get scheduled on the same node with 8 CPU.继续这个例子,假设 pod 被安排在具有 8 个 CPU 的同一节点上。 Now that they've been scheduled the resource requests don't matter any more.既然他们已经被安排好了,资源请求就不再重要了。 Neither pod has resource limits, but let's say the smaller pod actually tries to use 3 CPU and the larger pod (a multi-threaded stress test) uses 13 CPU.两个 Pod 都没有资源限制,但假设较小的 Pod 实际上尝试使用 3 个 CPU,而较大的 Pod(多线程压力测试)使用 13 个 CPU。 This is more than the physical capacity of the system, so the kernel will allocate processor cycles to the two processes.这超过了系统的物理容量,因此内核会为这两个进程分配处理器周期。

For CPU usage, if the node is overcommitted, you'll just see slow-downs in all of the processes.对于 CPU 使用率,如果节点过度使用,您只会看到所有进程的速度变慢。 Either memory or disk ("ephemeral storage") can cause pods to be Evicted and rescheduled on different nodes;内存或磁盘(“临时存储”)都可能导致 pod 被驱逐并在不同节点上重新调度; the pods that get evicted are the ones that exceed their resource requests by the most.被驱逐的 pod 是那些超过其资源请求最多的 pod。 Memory can also cause the node to run out of physical memory, and pods can get OOMKilled.内存也可能导致节点耗尽物理内存,并且 pod 可能会被 OOMKilled。

If every pod sets resource requests and limits to the same value then you do have an approximate guarantee that resources will be available, since nothing will be able to use more resource than the pod scheduler allocates it.如果每个pod 都将资源请求和限制设置为相同的值,那么您确实可以大致保证资源可用,因为没有什么能够使用比 pod 调度程序分配的资源更多的资源。 For an individual pod and for non-CPU resources, if resource requests and limits are the same, your pod won't get evicted if the node is overcommitted (because it can't exceed its requests).对于单个 pod 和非 CPU 资源,如果资源请求和限制相同,那么如果节点过度使用,您的 pod 不会被驱逐(因为它不能超过其请求)。 On the other hand, most processes won't generally use exactly their resource requests, and so setting requests high enough that you're guaranteed to not be evicted also means you're causing the node to have unused resources, and your cluster as a whole will be less efficient (need more nodes to do the same work and be more expensive) (but more reliable since pods won't get killed off as often).另一方面,大多数进程通常不会完全使用它们的资源请求,因此将请求设置得足够高以保证您不会被驱逐也意味着您导致节点具有未使用的资源,并且您的集群作为整体效率会降低(需要更多节点来完成相同的工作并且成本更高)(但更可靠,因为 pod 不会经常被杀死)。

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

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