@@ -33,8 +33,8 @@ limits so that the running container is not allowed to use more of that resource
33
33
than the limit you set. The kubelet also reserves at least the _request_ amount of
34
34
that system resource specifically for that container to use.
35
35
-->
36
- 当你定义 {{< glossary_tooltip text="Pod" term_id="pod" >}} 时可以选择性地为每个
37
- {{< glossary_tooltip text="容器" term_id="container" >}}设定所需要的资源数量。
36
+ 当你定义 {{< glossary_tooltip text="Pod" term_id="pod" >}}
37
+ 时可以选择性地为每个 {{< glossary_tooltip text="容器" term_id="container" >}}设定所需要的资源数量。
38
38
最常见的可设定资源是 CPU 和内存(RAM)大小;此外还有其他类型的资源。
39
39
40
40
当你为 Pod 中的 Container 指定了资源 ** request(请求)** 时,
@@ -51,7 +51,6 @@ kubelet 还会为容器预留所 **request(请求)** 数量的系统资源
51
51
52
52
If the node where a Pod is running has enough of a resource available, it's possible (and
53
53
allowed) for a container to use more resource than its `request` for that resource specifies.
54
- However, a container is not allowed to use more than its resource `limit`.
55
54
56
55
For example, if you set a `memory` request of 256 MiB for a container, and that container is in
57
56
a Pod scheduled to a Node with 8GiB of memory and no other Pods, then the container can try to use
@@ -60,33 +59,63 @@ more RAM.
60
59
## 请求和限制 {#requests-and-limits}
61
60
62
61
如果 Pod 运行所在的节点具有足够的可用资源,容器可能(且可以)使用超出对应资源
63
- ` request ` 属性所设置的资源量。不过,容器不可以使用超出其资源 ` limit `
64
- 属性所设置的资源量。
62
+ ` request ` 属性所设置的资源量。
65
63
66
64
例如,如果你将容器的 ` memory ` 的请求量设置为 256 MiB,而该容器所处的 Pod
67
65
被调度到一个具有 8 GiB 内存的节点上,并且该节点上没有其他 Pod
68
66
运行,那么该容器就可以尝试使用更多的内存。
69
67
70
68
<!--
71
- If you set a `memory` limit of 4GiB for that container, the kubelet (and
72
- {{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}) enforce the limit.
73
- The runtime prevents the container from using more than the configured resource limit. For example:
74
- when a process in the container tries to consume more than the allowed amount of memory,
75
- the system kernel terminates the process that attempted the allocation, with an out of memory
76
- (OOM) error.
69
+ Limits are a different story. Both `cpu` and `memory` limits are applied by the kubelet (and
70
+ {{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}),
71
+ and are ultimately enforced by the kernel. On Linux nodes, the Linux kernel
72
+ enforces limits with
73
+ {{< glossary_tooltip text="cgroups" term_id="cgroup" >}}.
74
+ The behavior of `cpu` and `memory` limit enforcement is slightly different.
75
+ -->
76
+ 限制是另一个话题。` cpu ` 限制和 ` memory ` 限制都由 kubelet
77
+ (以及 {{< glossary_tooltip text="容器运行时" term_id="container-runtime" >}})来应用,
78
+ 最终由内核强制执行。在 Linux 节点上,Linux 内核通过
79
+ {{< glossary_tooltip text="CGroup" term_id="cgroup" >}} 来强制执行限制。
80
+ ` cpu ` 限制和 ` memory ` 限制的执行行为略有不同。
77
81
78
- Limits can be implemented either reactively (the system intervenes once it sees a violation)
79
- or by enforcement (the system prevents the container from ever exceeding the limit). Different
80
- runtimes can have different ways to implement the same restrictions.
82
+ <!--
83
+ `cpu` limits are enforced by CPU throttling. When a container approaches
84
+ its `cpu` limit, the kernel will restrict access to the CPU corresponding to the
85
+ container's limit. Thus, a `cpu` limit is a hard limit the kernel enforces.
86
+ Containers may not use more CPU than is specified in their `cpu` limit.
87
+ -->
88
+ ` cpu ` 限制通过 CPU 节流机制来强制执行。
89
+ 当某容器接近其 ` cpu ` 限制值时,内核会基于容器的限制值来限制其对 CPU 的访问。
90
+ 因此,` cpu ` 限制是内核强制执行的一个硬性限制。容器不得使用超出其 ` cpu ` 限制所指定的 CPU 核数。
91
+
92
+ <!--
93
+ `memory` limits are enforced by the kernel with out of memory (OOM) kills. When
94
+ a container uses more than its `memory` limit, the kernel may terminate it. However,
95
+ terminations only happen when the kernel detects memory pressure. Thus, a
96
+ container that over allocates memory may not be immediately killed. This means
97
+ `memory` limits are enforced reactively. A container may use more memory than
98
+ its `memory` limit, but if it does, it may get killed.
81
99
-->
82
- 如果你将某容器的 ` memory ` 限制设置为 4 GiB,kubelet
83
- (和{{< glossary_tooltip text="容器运行时" term_id="container-runtime" >}})就会确保该限制生效。
84
- 容器运行时会禁止容器使用超出所设置资源限制的资源。
85
- 例如:当容器中进程尝试使用超出所允许内存量的资源时,系统内核会将尝试申请内存的进程终止,
86
- 并引发内存不足(OOM)错误。
100
+ ` memory ` 限制由内核使用 OOM(内存溢出)终止机制来强制执行。
101
+ 当某容器使用的内存超过其 ` memory ` 限制时,内核可以终止此容器。
102
+ 然而,终止只会在内核检测到内存压力时才会发生。
103
+ 因此,超配内存的容器可能不会被立即终止。
104
+ 这意味着 ` memory ` 限制是被动执行的。
105
+ 某容器可以使用超过其 ` memory ` 限制的内存,但如果这样做,此容器可能会被终止。
87
106
88
- 限制可以以被动方式来实现(系统会在发现违例时进行干预),或者通过强制生效的方式实现
89
- (系统会避免容器用量超出限制)。不同的容器运行时采用不同方式来实现相同的限制。
107
+ {{< note >}}
108
+ <!--
109
+ There is an alpha feature `MemoryQoS` which attempts to add more preemptive
110
+ limit enforcement for memory (as opposed to reactive enforcement by the OOM
111
+ killer). However, this effort is
112
+ [stalled](https://github.com/kubernetes/enhancements/tree/a47155b340/keps/sig-node/2570-memory-qos#latest-update-stalled)
113
+ due to a potential livelock situation a memory hungry can cause.
114
+ -->
115
+ 你可以使用一个 Alpha 特性 ` MemoryQoS ` 来尝试为内存添加执行更多的抢占限制
116
+ (这与 OOM Killer 的被动执行相反)。然而,由于可能会因内存饥饿造成活锁情形,
117
+ 所以这种尝试操作会被[ 卡滞] ( https://github.com/kubernetes/enhancements/tree/a47155b340/keps/sig-node/2570-memory-qos#latest-update-stalled ) 。
118
+ {{< /note >}}
90
119
91
120
{{< note >}}
92
121
<!--
@@ -153,7 +182,7 @@ Kubernetes API 服务器读取和修改的对象。
153
182
For each container, you can specify resource limits and requests,
154
183
including the following:
155
184
-->
156
- ## Pod 和 容器的资源请求和限制 {#resource-requests-and-limits-of-pod-and-container}
185
+ ## Pod 和容器的资源请求和限制 {#resource-requests-and-limits-of-pod-and-container}
157
186
158
187
针对每个容器,你都可以指定其资源限制和请求,包括如下选项:
159
188
@@ -171,7 +200,7 @@ a Pod.
171
200
For a particular resource, a *Pod resource request/limit* is the sum of the
172
201
resource requests/limits of that type for each container in the Pod.
173
202
-->
174
- 尽管你只能逐个容器地指定请求和限制值,考虑 Pod 的总体资源请求和限制也是有用的。
203
+ 尽管你只能逐个容器地指定请求和限制值,但考虑 Pod 的总体资源请求和限制也是有用的。
175
204
对特定资源而言,** Pod 的资源请求/限制** 是 Pod 中各容器对该类型资源的请求/限制的总和。
176
205
177
206
<!--
@@ -188,7 +217,7 @@ or a virtual machine running inside a physical machine.
188
217
189
218
### CPU 资源单位 {#meaning-of-cpu}
190
219
191
- CPU 资源的限制和请求以 “ cpu” 为单位。
220
+ CPU 资源的限制和请求以 ** cpu** 为单位。
192
221
在 Kubernetes 中,一个 CPU 等于 ** 1 个物理 CPU 核** 或者 ** 1 个虚拟核** ,
193
222
取决于节点是一台物理主机还是运行在某物理主机上的虚拟机。
194
223
@@ -201,10 +230,10 @@ expression `100m`, which can be read as "one hundred millicpu". Some people say
201
230
"one hundred millicores", and this is understood to mean the same thing.
202
231
-->
203
232
你也可以表达带小数 CPU 的请求。
204
- 当你定义一个容器,将其 ` spec.containers[].resources.requests.cpu ` 设置为 0.5 时,
205
- 你所请求的 CPU 是你请求 ` 1.0 ` CPU 时的一半。
206
- 对于 CPU 资源单位, [ 数量] ( /zh-cn/docs/reference/kubernetes-api/common-definitions/quantity/ )
207
- 表达式 ` 0.1 ` 等价于表达式 ` 100m ` ,可以看作 “100 millicpu”。
233
+ 当你定义一个容器,将其 ` spec.containers[].resources.requests.cpu ` 设置为 ` 0.5 ` 时,
234
+ 你所请求的 CPU 是你请求 ` 1.0 ` CPU 时的一半。对于 CPU 资源单位,
235
+ [ 数量] ( /zh-cn/docs/reference/kubernetes-api/common-definitions/quantity/ ) 表达式 ` 0.1 `
236
+ 等价于表达式 ` 100m ` ,可以看作 “100 millicpu”。
208
237
有些人说成是“一百毫核”,其实说的是同样的事情。
209
238
210
239
<!--
@@ -213,7 +242,7 @@ CPU resource is always specified as an absolute amount of resource, never as a r
213
242
runs on a single-core, dual-core, or 48-core machine.
214
243
-->
215
244
CPU 资源总是设置为资源的绝对数量而非相对数量值。
216
- 例如,无论容器运行在单核、双核或者 48- 核的机器上,` 500m ` CPU 表示的是大约相同的计算能力 。
245
+ 例如,无论容器运行在单核、双核或者 48 核的机器上,` 500m ` CPU 表示的是大约相同的算力 。
217
246
218
247
{{< note >}}
219
248
<!--
@@ -347,7 +376,7 @@ limits you defined.
347
376
当 kubelet 将容器作为 Pod 的一部分启动时,它会将容器的 CPU 和内存请求与限制信息传递给容器运行时。
348
377
349
378
在 Linux 系统上,容器运行时通常会配置内核
350
- {{< glossary_tooltip text="CGroups " term_id="cgroup" >}},负责应用并实施所定义的请求。
379
+ {{< glossary_tooltip text="CGroup " term_id="cgroup" >}},负责应用并实施所定义的请求。
351
380
352
381
<!--
353
382
- The CPU limit defines a hard ceiling on how much CPU time the container can use.
@@ -356,13 +385,13 @@ limits you defined.
356
385
-->
357
386
- CPU 限制定义的是容器可使用的 CPU 时间的硬性上限。
358
387
在每个调度周期(时间片)期间,Linux 内核检查是否已经超出该限制;
359
- 内核会在允许该 cgroup 恢复执行之前会等待。
388
+ 内核会在允许该 CGroup 恢复执行之前会等待。
360
389
<!--
361
390
- The CPU request typically defines a weighting. If several different containers (cgroups)
362
391
want to run on a contended system, workloads with larger CPU requests are allocated more
363
392
CPU time than workloads with small requests.
364
393
-->
365
- - CPU 请求值定义的是一个权重值。如果若干不同的容器(CGroups )需要在一个共享的系统上竞争运行,
394
+ - CPU 请求值定义的是一个权重值。如果若干不同的容器(CGroup )需要在一个共享的系统上竞争运行,
366
395
CPU 请求值大的负载会获得比请求值小的负载更多的 CPU 时间。
367
396
<!--
368
397
- The memory request is mainly used during (Kubernetes) Pod scheduling. On a node that uses
@@ -378,7 +407,7 @@ limits you defined.
378
407
to allocate memory. If that process is the container's PID 1, and the container is marked
379
408
as restartable, Kubernetes restarts the container.
380
409
-->
381
- - 内存限制定义的是 cgroup 的内存限制。如果容器尝试分配的内存量超出限制,
410
+ - 内存限制定义的是 CGroup 的内存限制。如果容器尝试分配的内存量超出限制,
382
411
则 Linux 内核的内存不足处理子系统会被激活,并停止尝试分配内存的容器中的某个进程。
383
412
如果该进程在容器中 PID 为 1,而容器被标记为可重新启动,则 Kubernetes
384
413
会重新启动该容器。
@@ -499,9 +528,11 @@ for additional enforcement.
499
528
If you specify a `spec.containers[].resources.limits.memory` for each Pod,
500
529
then the maximum size of an `emptyDir` volume will be the pod's memory limit.
501
530
-->
502
- 如果你在管理集群或命名空间,还可以设置限制内存使用的 [ResourceQuota](/zh-cn/docs/concepts/policy/resource-quotas/);
503
- 你可能还希望定义一个 [LimitRange](/zh-cn/docs/concepts/policy/limit-range/) 以施加额外的限制。如果为每个 Pod
504
- 指定 `spec.containers[].resources.limits.memory`,那么 `emptyDir` 卷的最大尺寸将是该 Pod 的内存限制。
531
+ 如果你在管理集群或命名空间,还可以设置限制内存使用的
532
+ [ResourceQuota](/zh-cn/docs/concepts/policy/resource-quotas/);
533
+ 你可能还希望定义一个 [LimitRange](/zh-cn/docs/concepts/policy/limit-range/)
534
+ 以施加额外的限制。如果为每个 Pod 指定 `spec.containers[].resources.limits.memory`,
535
+ 那么 `emptyDir` 卷的最大尺寸将是 Pod 的内存限制。
505
536
506
537
<!--
507
538
As an alternative, a cluster administrator can enforce size limits for
@@ -568,9 +599,9 @@ the resource quota is not enforced on ephemeral-storage.
568
599
为了使临时性存储的资源配额生效,需要完成以下两个步骤:
569
600
570
601
* 管理员在命名空间中设置临时性存储的资源配额。
571
- * 用户需要在 Pod spec 中指定临时性存储资源的限制 。
602
+ * 用户需要在 Pod 规约中指定临时性存储资源的限制 。
572
603
573
- 如果用户在 Pod spec 中未指定临时性存储资源的限制 ,
604
+ 如果用户在 Pod 规约中未指定临时性存储资源的限制 ,
574
605
则临时性存储的资源配额不会生效。
575
606
{{< /note >}}
576
607
0 commit comments