简体   繁体   English

Kubernetes - 如果不设置 pod CPU 请求或限制会发生什么?

[英]Kubernetes - what happens if you don't set a pod CPU request or limit?

I understand the concept of setting a request or a limit on a Kubernetes pod for both CPU and/or memory resources but I'm trying to understand what happens if you don't set either request or limit for say a CPU?我理解为CPU和/或memory资源在 Kubernetes pod 上设置requestlimit的概念,但我想了解如果您不为 CPU 设置requestlimit会发生什么?

We have configured an NGINX pod but it doesn't have either a request or limit set for its CPU .我们已经配置了一个 NGINX pod,但它没有为其CPU设置requestlimit I'm assuming it will have at a minimum 1 millicore and will give as much millicores to that pod as it needs and is available on the node.我假设它至少有1 millicore ,并且会根据需要为该 pod 提供尽可能多的毫核,并且在节点上可用。 If the node has exhausted all available cores, then does it just stay stuck at 1 millicore?如果节点用尽了所有可用的内核,那么它会停留在 1 毫内核吗?

what happens if you don't set either request or limit for say a CPU?如果您没有为 CPU 设置请求或限制,会发生什么?

When you don't specify a request for CPU, you're saying you don't care how much CPU time the process running in your container is allotted.当您没有指定 CPU 请求时,您是在说您不关心容器中运行的进程分配了多少 CPU 时间。

In the worst case, it may not get any CPU time at all (this happens when a heavy demand by other processes exists on the CPU).在最坏的情况下,它可能根本得不到任何 CPU 时间(当 CPU 上存在其他进程的大量需求时会发生这种情况)。 Although this may be fine for low-priority batch jobs, which aren't time-critical, it obviously isn't appropriate for containers handling user requests.尽管这对于时间要求不高的低优先级批处理作业可能很好,但显然不适合处理用户请求的容器。

you're also requesting 1 millicore of memory for the container.您还为容器请求1 millicore memory。 By doing that, you're saying that you expect the processes running inside the container to use at most N mebibytes of RAM.通过这样做,您是说您希望在容器内运行的进程最多使用N mebibytes的 RAM。 They might use less, but you're not expecting them to use more than that in normal circumstances.他们可能会使用更少,但您不会期望他们在正常情况下使用更多。

Understanding how resource requests affect scheduling了解资源请求如何影响调度

By specifying resource requests, you're specifying the minimum amount of resources your pod needs.通过指定资源请求,您可以指定 pod 所需的最小资源量。 This information is what the Scheduler uses when scheduling the pod to a node.此信息是调度程序在将 pod 调度到节点时使用的信息。

Each node has a certain amount of CPU and memory it can allocate to pods.每个节点都有一定数量的 CPU 和 memory 可以分配给 pod。 When scheduling a pod, the Scheduler will only consider nodes with enough unallocated resources to meet the pod's resource requirements.在调度 Pod 时,Scheduler 只会考虑具有足够未分配资源的节点来满足 Pod 的资源需求。

If the amount of unallocated CPU or memory is less than what the pod requests, Kubernetes will not schedule the pod to that node, because the node can't provide the minimum amount required by the pod.如果未分配的 CPU 或 memory 的数量小于 pod 请求的数量,Kubernetes 将不会将 pod 调度到该节点,因为该节点无法提供该 pod 所需的最小数量。

Understanding what will happened if Exceeding the limits了解如果超出限制会发生什么

With CPU带 CPU

CPU is a compressible resource, and it's only natural for a process to want to consume all of the CPU time when not waiting for an I/O operation. CPU 是一种可压缩资源,进程在不等待 I/O 操作时想要消耗所有 CPU 时间是很自然的。

a process' CPU usage is throttled, so when a CPU limit is set for a container, the process isn't given more CPU time than the configured limit.进程的 CPU 使用率受到限制,因此当为容器设置 CPU 限制时,不会为进程分配比配置限制更多的 CPU 时间。

With Memory带 Memory

With memory, it's different.与 memory 不同。 When a process tries to allocate memory over its limit, the process is killed (it's said the container is OOMKilled , where OOM stands for Out Of Memory).当一个进程试图分配 memory 超过其限制时,该进程被杀死(据说容器是OOMKilled ,其中OOM代表内存不足)。 If the pod's restart policy is set to Always or OnFailure , the process is restarted immediately, so you may not even notice it getting killed.如果 pod 的重启策略设置为 Always 或OnFailure ,进程会立即重启,所以你甚至可能不会注意到它被杀死了。 But if it keeps going over the memory limit and getting killed, Kubernetes will begin restarting it with increasing delays between restarts.但是,如果它继续超过 memory 限制并被杀死,Kubernetes 将开始重新启动它,并且重新启动之间的延迟会增加。 You'll see a CrashLoopBackOff status in that case.在这种情况下,您会看到CrashLoopBackOff状态。

kubectl get po
NAME        READY     STATUS             RESTARTS   AGE
memoryhog    0/1   CrashLoopBackOff         3       1m

Note: The CrashLoopBackOff status doesn't mean the Kubelet has given up.注意: CrashLoopBackOff状态并不意味着 Kubelet 已经放弃。 It means that after each crash, the Kubelet is increasing the time period before restarting the container.这意味着每次崩溃后,Kubelet 都会增加重新启动容器之前的时间段。

Understand To examine why the container crashed了解检查容器崩溃的原因

kubectl describe pod
Name:
...
Containers:
main: ...
    State: Terminated
      Reason: OOMKilled
...

Pay attention to the Reason attribute OOMKilled .注意原因属性OOMKilled The current container was killed because it was out of memory (OOM).当前容器被杀死,因为它超出了 memory (OOM)。

I understand the concept of setting a request or a limit on a Kubernetes pod for both CPU and/or memory resources but I'm trying to understand what happens if you don't set either request or limit for say a CPU?我理解为CPU和/或memory资源在 Kubernetes pod 上设置requestlimit的概念,但我想了解如果您不为 CPU 设置requestlimit会发生什么?

We have configured an NGINX pod but it doesn't have either a request or limit set for its CPU .我们已经配置了一个 NGINX pod,但它没有为其CPU设置requestlimit I'm assuming it will have at a minimum 1 millicore and will give as much millicores to that pod as it needs and is available on the node.我假设它至少有1 millicore ,并且会根据需要为该 pod 提供尽可能多的毫核,并且在节点上可用。 If the node has exhausted all available cores, then does it just stay stuck at 1 millicore?如果节点用尽了所有可用的内核,那么它会停留在 1 毫内核吗?

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

相关问题 如果 Kube.netes pod 超出其 cpu 资源“限制”会怎样? - What happens if a Kubernetes pod exceeds its cpu resources 'limit'? 为什么 Kubernetes 不为 pod 设置 1 个 CPU 限制? - Why doesn't Kubernetes set a 1 CPU limit for a pod? 为Pod分配特定的CPU资源-kubernetes.io/limit-ranger:'LimitRanger插件集:容器Elasticsearch的CPU请求' - Assigning specific CPU resources to pod - kubernetes.io/limit-ranger: 'LimitRanger plugin set: cpu request for container elasticsearch' 如果Kubernetes Pod超出其内存资源``限制''会怎样? - What happens if a Kubernetes pod exceeds its memory resources 'limit'? 缩小 Kube.netes Pod 时会发生什么? - What happens when you scale down a Kubernetes Pod? Kubernetes 使用什么来计算 CPU 比率、请求或限制? - What Kubernetes uses to calculate the CPU ratio, request or limit? 为什么实际CPU利用率百分比超过Kubernetes中的Pod CPU限制 - Why the actual CPU utilization percentage exceeds Pod CPU limit in Kubernetes 在kubernetes中对Pod大小(CPU,内存)的建议是什么 - what are recommendation for pod size(CPU, memory) in kubernetes Kube.netes:哪个 pod 在节点上使用最多的 CPU? - Kubernetes: What pod uses most CPU on a node? Kubernetes。 如果请求大小大于 pod 的 RAM 会怎样? - Kubernetes. What happens if the request size is greater than the pod's RAM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM