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

n00*_*00b 9 kubernetes

我理解在 Kubernetes pod 上为两者和/或资源设置 arequest或 a的概念,但我试图了解如果您不为 CPU设置其中任何一个或 a会发生什么?limitCPUmemoryrequestlimit

我们已经配置了一个 NGINX pod,但requestlimitCPU. 我假设它至少有,1 millicore并且会根据需要为该 Pod 提供尽可能多的毫核,并且在节点上可用。如果节点耗尽了所有可用核心,那么它是否会停留在 1 毫核心?

VKa*_*atz 12

如果您没有为 CPU 设置请求或限制,会发生什么情况?

\n
\n

当您不\xe2\x80\x99t 指定CPU 请求时,\xe2\x80\x99 表示您不\xe2\x80\x99t\n关心容器中运行的进程\n分配了多少CPU 时间。

\n
\n
\n

在最坏的情况下,它可能根本无法获得任何 CPU 时间(当其他进程对 CPU 存在大量需求时,就会发生这种情况)。虽然这对于时间关键的低优先级批处理作业来说可能没问题,但它显然不适合处理用户请求的容器。

\n
\n
\n

you\xe2\x80\x99 也在1 millicore为容器请求内存。通过这样做,您\xe2\x80\x99 表示您希望容器内运行的进程最多使用大部分N mebibytesRAM。他们\n可能使用较少,但你\xe2\x80\x99不希望他们在正常情况下使用更多\xe2\x80\x99。

\n
\n

了解资源请求如何影响调度

\n
\n

通过指定资源请求,您\xe2\x80\x99 指定了 pod 所需的最小资源量。调度程序在将 Pod 调度到节点时使用此信息。

\n
\n
\n

每个节点都有一定数量的 CPU 和内存可以分配给 Pod。在调度 pod 时,调度程序只会考虑具有足够未分配资源的节点,以满足 pod\xe2\x80\x99s 资源需求。

\n
\n
\n

如果未分配的 CPU 或内存量小于 pod 请求的量,Kubernetes 不会将 pod 调度到该节点,因为该节点无法提供 pod 所需的最小数量。

\n
\n

了解超出限制会发生什么

\n

带CPU

\n
\n

CPU 是一种可压缩资源,进程在不等待 I/O 操作时想要消耗所有 CPU 时间是很自然的。

\n
\n
\n

a process\xe2\x80\x99 CPU usage is throttled, so when a CPU limit is set for a container, the process isn\xe2\x80\x99t given more CPU time than the configured limit.

\n
\n

With Memory

\n
\n

With memory, it\xe2\x80\x99s different. When a process tries to allocate memory over its limit, the process is killed (it\xe2\x80\x99s said the container is OOMKilled, where OOM stands for Out Of Memory).\nIf the pod\xe2\x80\x99s restart policy is set to Always or OnFailure, the process is restarted immediately, so you may not even notice it getting killed. But if it keeps going over the memory limit and getting killed, Kubernetes will begin restarting it with increasing delays between restarts. You\xe2\x80\x99ll see a CrashLoopBackOff status in that case.

\n
\n
kubectl get po\nNAME        READY     STATUS             RESTARTS   AGE\nmemoryhog    0/1   CrashLoopBackOff         3       1m\n
Run Code Online (Sandbox Code Playgroud)\n

Note: The CrashLoopBackOff status doesn\xe2\x80\x99t mean the Kubelet has given up. It means that after each crash, the Kubelet is increasing the time period before restarting the container.

\n

Understand To examine why the container crashed

\n
kubectl describe pod\nName:\n...\nContainers:\nmain: ...\n    State: Terminated\n      Reason: OOMKilled\n...\n
Run Code Online (Sandbox Code Playgroud)\n
\n

Pay attention to the Reason attribute OOMKilled. The current container was killed because it was out of memory (OOM).

\n
\n