@@ -5,11 +5,9 @@ weight: 10
5
5
---
6
6
7
7
<!--
8
- ---
9
8
title: Assign Memory Resources to Containers and Pods
10
9
content_type: task
11
10
weight: 10
12
- ---
13
11
-->
14
12
15
13
<!-- overview -->
@@ -19,34 +17,33 @@ This page shows how to assign a memory *request* and a memory *limit* to a
19
17
Container. A Container is guaranteed to have as much memory as it requests,
20
18
but is not allowed to use more memory than its limit.
21
19
-->
22
- 此页面显示如何将内存 * 请求* (request)和内存 * 限制* (limit)分配给一个容器。我们保障容器拥有它请求数量的内存,但不允许使用超过限制数量的内存。
23
-
24
-
25
-
20
+ 此页面展示如何将内存 * 请求* (request)和内存 * 限制* (limit)分配给一个容器。
21
+ 我们保障容器拥有它请求数量的内存,但不允许使用超过限制数量的内存。
26
22
27
23
## {{% heading "prerequisites" %}}
28
24
29
-
30
25
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
31
26
32
27
<!--
33
28
Each node in your cluster must have at least 300 MiB of memory.
34
29
-->
35
- 您集群中的每个节点必须拥有至少 300 MiB 的内存。
30
+ 你集群中的每个节点必须拥有至少 300 MiB 的内存。
36
31
37
32
<!--
38
33
A few of the steps on this page require you to run the
39
- [metrics-server](https://github.com/kubernetes-incubator /metrics-server)
34
+ [metrics-server](https://github.com/kubernetes-sigs /metrics-server)
40
35
service in your cluster. If you have the metrics-server
41
36
running, you can skip those steps.
42
37
-->
43
- 该页面上的一些步骤要求您在集群中运行 [ metrics-server] ( https://github.com/kubernetes-incubator/metrics-server ) 服务。如果您已经有在运行中的 metrics-server,则可以跳过这些步骤。
38
+ 该页面上的一些步骤要求你在集群中运行
39
+ [ metrics-server] ( https://github.com/kubernetes-sigs/metrics-server ) 服务。
40
+ 如果你已经有在运行中的 metrics-server,则可以跳过这些步骤。
44
41
45
42
<!--
46
43
If you are running Minikube, run the following command to enable the
47
44
metrics-server:
48
45
-->
49
- 如果您运行的是 Minikube,可以运行下面的命令启用 metrics-server:
46
+ 如果你运行的是 Minikube,可以运行下面的命令启用 metrics-server:
50
47
51
48
``` shell
52
49
minikube addons enable metrics-server
@@ -68,13 +65,11 @@ reference to `metrics.k8s.io`.
68
65
-->
69
66
如果资源指标 API 可用,则输出结果将包含对 ` metrics.k8s.io ` 的引用信息。
70
67
71
- ``` shell
68
+ ```
72
69
NAME
73
70
v1beta1.metrics.k8s.io
74
71
```
75
72
76
-
77
-
78
73
<!-- steps -->
79
74
80
75
<!--
@@ -106,7 +101,7 @@ for the Pod:
106
101
要为容器指定内存请求,请在容器资源清单中包含 ` resources:requests ` 字段。
107
102
同理,要指定内存限制,请包含 ` resources:limits ` 。
108
103
109
- 在本练习中,您将创建一个拥有一个容器的 Pod。
104
+ 在本练习中,你将创建一个拥有一个容器的 Pod。
110
105
容器将会请求 100 MiB 内存,并且内存会被限制在 200 MiB 以内。
111
106
这是 Pod 的配置文件:
112
107
@@ -203,16 +198,18 @@ restarted, the kubelet restarts it, as with any other type of runtime failure.
203
198
-->
204
199
## 超过容器限制的内存
205
200
206
- 当节点拥有足够的可用内存时,容器可以使用其请求的内存。但是,容器不允许使用超过其限制的内存。
207
- 如果容器分配的内存超过其限制,该容器会成为被终止的候选容器。如果容器继续消耗超出其限制的内存,则终止容器。
201
+ 当节点拥有足够的可用内存时,容器可以使用其请求的内存。
202
+ 但是,容器不允许使用超过其限制的内存。
203
+ 如果容器分配的内存超过其限制,该容器会成为被终止的候选容器。
204
+ 如果容器继续消耗超出其限制的内存,则终止容器。
208
205
如果终止的容器可以被重启,则 kubelet 会重新启动它,就像其他任何类型的运行时失败一样。
209
206
210
207
<!--
211
208
In this exercise, you create a Pod that attempts to allocate more memory than its limit.
212
209
Here is the configuration file for a Pod that has one Container with a
213
210
memory request of 50 MiB and a memory limit of 100 MiB:
214
211
-->
215
- 在本练习中,您将创建一个 Pod,尝试分配超出其限制的内存。
212
+ 在本练习中,你将创建一个 Pod,尝试分配超出其限制的内存。
216
213
这是一个 Pod 的配置文件,其拥有一个容器,该容器的内存请求为 50 MiB,内存限制为 100 MiB:
217
214
218
215
{{< codenew file="pods/resource/memory-request-limit-2.yaml" >}}
@@ -223,7 +220,7 @@ will attempt to allocate 250 MiB of memory, which is well above the 100 MiB limi
223
220
224
221
Create the Pod:
225
222
-->
226
- 在配置文件的 ` args ` 部分中,您可以看到容器会尝试分配 250 MiB 内存,这远高于 100 MiB 的限制。
223
+ 在配置文件的 ` args ` 部分中,你可以看到容器会尝试分配 250 MiB 内存,这远高于 100 MiB 的限制。
227
224
228
225
创建 Pod:
229
226
@@ -277,7 +274,8 @@ lastState:
277
274
The Container in this exercise can be restarted, so the kubelet restarts it. Repeat
278
275
this command several times to see that the Container is repeatedly killed and restarted:
279
276
-->
280
- 本练习中的容器可以被重启,所以 kubelet 会重启它。多次运行下面的命令,可以看到容器在反复的被杀死和重启:
277
+ 本练习中的容器可以被重启,所以 kubelet 会重启它。
278
+ 多次运行下面的命令,可以看到容器在反复的被杀死和重启:
281
279
282
280
``` shell
283
281
kubectl get pod memory-demo-2 --namespace=mem-example
@@ -371,8 +369,8 @@ of any Node in your cluster.
371
369
-->
372
370
Pod 的调度基于请求。只有当节点拥有足够满足 Pod 内存请求的内存时,才会将 Pod 调度至节点上运行。
373
371
374
- 在本练习中,你将创建一个 Pod,其内存请求超过了您集群中的任意一个节点所拥有的内存 。
375
- 这是该 Pod 的配置文件,其拥有一个请求 1000 GiB 内存的容器,这应该超过了您集群中任何节点的容量 。
372
+ 在本练习中,你将创建一个 Pod,其内存请求超过了你集群中的任意一个节点所拥有的内存 。
373
+ 这是该 Pod 的配置文件,其拥有一个请求 1000 GiB 内存的容器,这应该超过了你集群中任何节点的容量 。
376
374
377
375
{{< codenew file="pods/resource/memory-request-limit-3.yaml" >}}
378
376
@@ -397,7 +395,8 @@ kubectl get pod memory-demo-3 --namespace=mem-example
397
395
<!--
398
396
The output shows that the Pod status is PENDING. That is, the Pod is not scheduled to run on any Node, and it will remain in the PENDING state indefinitely:
399
397
-->
400
- 输出结果显示:Pod 处于 PENDING 状态。这意味着,该 Pod 没有被调度至任何节点上运行,并且它会无限期的保持该状态:
398
+ 输出结果显示:Pod 处于 PENDING 状态。
399
+ 这意味着,该 Pod 没有被调度至任何节点上运行,并且它会无限期的保持该状态:
401
400
402
401
```
403
402
kubectl get pod memory-demo-3 --namespace=mem-example
@@ -436,7 +435,9 @@ For example, the following represent approximately the same value:
436
435
-->
437
436
## 内存单位
438
437
439
- 内存资源的基本单位是字节(byte)。您可以使用这些后缀之一,将内存表示为纯整数或定点整数:E、P、T、G、M、K、Ei、Pi、Ti、Gi、Mi、Ki。例如,下面是一些近似相同的值:
438
+ 内存资源的基本单位是字节(byte)。你可以使用这些后缀之一,将内存表示为
439
+ 纯整数或定点整数:E、P、T、G、M、K、Ei、Pi、Ti、Gi、Mi、Ki。
440
+ 例如,下面是一些近似相同的值:
440
441
441
442
``` shell
442
443
128974848, 129e6, 129M , 123Mi
@@ -469,12 +470,13 @@ Container is automatically assigned the default limit. Cluster administrators ca
469
470
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
470
471
to specify a default value for the memory limit.
471
472
-->
472
- * 容器可无限制地使用内存。容器可以使用其所在节点所有的可用内存,进而可能导致该节点调用 OOM Killer。
473
- 此外,如果发生 OOM Kill,没有资源限制的容器将被杀掉的可行性更大。
473
+ * 容器可无限制地使用内存。容器可以使用其所在节点所有的可用内存,
474
+ 进而可能导致该节点调用 OOM Killer。
475
+ 此外,如果发生 OOM Kill,没有资源限制的容器将被杀掉的可行性更大。
474
476
475
477
* 运行的容器所在命名空间有默认的内存限制,那么该容器会被自动分配默认限制。
476
- 集群管理员可用使用 [ LimitRange] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
477
- 来指定默认的内存限制。
478
+ 集群管理员可用使用 [ LimitRange] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
479
+ 来指定默认的内存限制。
478
480
479
481
<!--
480
482
## Motivation for memory requests and limits
@@ -486,7 +488,9 @@ scheduled. By having a memory limit that is greater than the memory request, you
486
488
-->
487
489
## 内存请求和限制的目的
488
490
489
- 通过为集群中运行的容器配置内存请求和限制,您可以有效利用集群节点上可用的内存资源。通过将 Pod 的内存请求保持在较低水平,您可以更好地安排 Pod 调度。通过让内存限制大于内存请求,您可以完成两件事:
491
+ 通过为集群中运行的容器配置内存请求和限制,你可以有效利用集群节点上可用的内存资源。
492
+ 通过将 Pod 的内存请求保持在较低水平,你可以更好地安排 Pod 调度。
493
+ 通过让内存限制大于内存请求,你可以完成两件事:
490
494
491
495
<!--
492
496
* The Pod can have bursts of activity where it makes use of memory that happens to be available.
@@ -508,34 +512,46 @@ Delete your namespace. This deletes all the Pods that you created for this task:
508
512
kubectl delete namespace mem-example
509
513
```
510
514
511
-
512
-
513
515
## {{% heading "whatsnext" %}}
514
516
517
+ <!--
518
+ ### For app developers
519
+
520
+ * [Assign CPU Resources to Containers and Pods](/docs/tasks/configure-pod-container/assign-cpu-resource/)
515
521
522
+ * [Configure Quality of Service for Pods](/docs/tasks/configure-pod-container/quality-service-pod/)
523
+ -->
516
524
### 应用开发者扩展阅读
517
525
518
526
* [ 为容器和 Pod 分配 CPU 资源] ( /zh/docs/tasks/configure-pod-container/assign-cpu-resource/ )
519
527
520
528
* [ 配置 Pod 的服务质量] ( /zh/docs/tasks/configure-pod-container/quality-service-pod/ )
521
529
522
- ### 集群管理员扩展阅读
523
-
524
- * [ 为命名空间配置默认的内存请求和限制] ( /zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/ )
525
530
526
- * [ 为命名空间配置默认的 CPU 请求和限制] ( /zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/ )
531
+ <!--
532
+ ### For cluster administrators
527
533
528
- * [ 配置命名空间的最小和最大内存约束 ] ( /zh/ docs/tasks/administer-cluster/manage-resources/memory-constraint -namespace/ )
534
+ * [Configure Default Memory Requests and Limits for a Namespace ](/docs/tasks/administer-cluster/manage-resources/memory-default -namespace/)
529
535
530
- * [ 配置命名空间的最小和最大 CPU 约束 ] ( /zh/ docs/tasks/administer-cluster/manage-resources/cpu-constraint -namespace/ )
536
+ * [Configure Default CPU Requests and Limits for a Namespace ](/docs/tasks/administer-cluster/manage-resources/cpu-default -namespace/)
531
537
532
- * [ 为命名空间配置内存和 CPU 配额 ] ( /zh/ docs/tasks/administer-cluster/manage-resources/quota- memory-cpu -namespace/ )
538
+ * [Configure Minimum and Maximum Memory Constraints for a Namespace ](/docs/tasks/administer-cluster/manage-resources/memory-constraint -namespace/)
533
539
534
- * [ 配置命名空间下 Pod 总数] ( /zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/ )
535
-
536
- * [ 配置 API 对象配额] ( /zh/docs/tasks/administer-cluster/quota-api-object/ )
540
+ * [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
537
541
542
+ * [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
538
543
544
+ * [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
539
545
546
+ * [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
547
+ -->
548
+ ### 集群管理员扩展阅读
540
549
550
+ * [ 为命名空间配置默认的内存请求和限制] ( /zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/ )
551
+ * [ 为命名空间配置默认的 CPU 请求和限制] ( /zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/ )
552
+ * [ 配置命名空间的最小和最大内存约束] ( /zh/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/ )
553
+ * [ 配置命名空间的最小和最大 CPU 约束] ( /zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/ )
554
+ * [ 为命名空间配置内存和 CPU 配额] ( /zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/ )
555
+ * [ 配置命名空间下 Pod 总数] ( /zh/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/ )
556
+ * [ 配置 API 对象配额] ( /zh/docs/tasks/administer-cluster/quota-api-object/ )
541
557
0 commit comments