Skip to content

Commit c0cf43b

Browse files
authored
Merge pull request #33831 from TinySong/task-6
[zh] sync memory-default-namespace.md and reconfigure-kubelet.md
2 parents 8d3a386 + 1928ca2 commit c0cf43b

File tree

2 files changed

+129
-666
lines changed

2 files changed

+129
-666
lines changed

content/zh/docs/tasks/administer-cluster/manage-resources/memory-default-namespace.md

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,55 @@
22
title: 为命名空间配置默认的内存请求和限制
33
content_type: task
44
weight: 10
5+
description: >-
6+
为命名空间定义默认的内存资源限制,在该命名空间中每个新建的 Pod 都会被配置上内存资源限制。
57
---
68

79
<!--
810
title: Configure Default Memory Requests and Limits for a Namespace
911
content_type: task
1012
weight: 10
13+
description: >-
14+
Define a default memory resource limit for a namespace, so that every new Pod
15+
in that namespace has a memory resource limit configured.
1116
-->
1217

1318
<!-- overview -->
1419

1520
<!--
16-
This page shows how to configure default memory requests and limits for a namespace.
17-
If a Container is created in a namespace that has a default memory limit, and the Container
18-
does not specify its own memory limit, then the Container is assigned the default memory limit.
21+
This page shows how to configure default memory requests and limits for a
22+
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
23+
24+
A Kubernetes cluster can be divided into namespaces. Once you have a namespace that
25+
has a default memory
26+
[limit](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits),
27+
and you then try to create a Pod with a container that does not specify its own memory
28+
limit, then the
29+
{{< glossary_tooltip text="control plane" term_id="control-plane" >}} assigns the default
30+
memory limit to that container.
31+
1932
Kubernetes assigns a default memory request under certain conditions that are explained later in this topic.
2033
-->
34+
本章介绍如何为{{< glossary_tooltip text="命名空间" term_id="namespace" >}}配置默认的内存请求和限制。
35+
36+
一个 Kubernetes 集群可被划分为多个命名空间。
37+
如果你在具有默认内存[限制](/zh/docs/concepts/configuration/manage-resources-containers/#requests-and-limits)
38+
的命名空间内尝试创建一个 Pod,并且这个 Pod 中的容器没有声明自己的内存资源限制,
39+
那么{{< glossary_tooltip text="控制面" term_id="control-plane" >}}会为该容器设定默认的内存限制。
2140

22-
本文介绍怎样给命名空间配置默认的内存请求和限制。
23-
如果在一个有默认内存限制的命名空间创建容器,该容器没有声明自己的内存限制时,
24-
将会被指定默认内存限制。
2541
Kubernetes 还为某些情况指定了默认的内存请求,本章后面会进行介绍。
2642

2743
## {{% heading "prerequisites" %}}
2844

29-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
45+
{{< include "task-tutorial-prereqs.md" >}}
3046

3147
<!--
48+
You must have access to create namespaces in your cluster.
49+
3250
Each node in your cluster must have at least 2 GiB of memory.
3351
-->
52+
在你的集群里你必须要有创建命名空间的权限。
53+
3454
你的集群中的每个节点必须至少有 2 GiB 的内存。
3555

3656
<!-- steps -->
@@ -52,12 +72,14 @@ kubectl create namespace default-mem-example
5272
<!--
5373
## Create a LimitRange and a Pod
5474
55-
Here's the configuration file for a LimitRange object. The configuration specifies
56-
a default memory request and a default memory limit.
75+
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}.
76+
The manifest specifies a default memory
77+
request and a default memory limit.
5778
-->
5879
## 创建 LimitRange 和 Pod
5980

60-
这里给出了一个限制范围对象的配置文件。该配置声明了一个默认的内存请求和一个默认的内存限制。
81+
以下为 {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}} 的示例清单。
82+
清单中声明了默认的内存请求和默认的内存限制。
6183

6284
{{< codenew file="admin/resource/memory-defaults.yaml" >}}
6385

@@ -71,19 +93,20 @@ kubectl apply -f https://k8s.io/examples/admin/resource/memory-defaults.yaml --n
7193
```
7294

7395
<!--
74-
Now if a Container is created in the default-mem-example namespace, and the
75-
Container does not specify its own values for memory request and memory limit,
76-
the Container is given a default memory request of 256 MiB and a default
77-
memory limit of 512 MiB.
96+
Now if you create a Pod in the default-mem-example namespace, and any container
97+
within that Pod does not specify its own values for memory request and memory limit,
98+
then the {{< glossary_tooltip text="control plane" term_id="control-plane" >}}
99+
applies default values: a memory request of 256MiB and a memory limit of 512MiB.
78100
79-
Here's the configuration file for a Pod that has one Container. The Container
101+
Here's an example manifest for a Pod that has one container. The container
80102
does not specify a memory request and limit.
81103
-->
82-
现在,如果在 default-mem-example 命名空间创建容器,并且该容器没有声明自己的内存请求和限制值,
83-
它将被指定默认的内存请求 256 MiB 和默认的内存限制 512 MiB。
104+
现在如果你在 default-mem-example 命名空间中创建一个 Pod,
105+
并且该 Pod 中所有容器都没有声明自己的内存请求和内存限制,
106+
{{< glossary_tooltip text="控制面" term_id="control-plane" >}}
107+
会将内存的默认请求值 256MiB 和默认限制值 512MiB 应用到 Pod 上。
84108

85-
下面是具有一个容器的 Pod 的配置文件。
86-
容器未指定内存请求和限制。
109+
以下为只包含一个容器的 Pod 的清单。该容器没有声明内存请求和限制。
87110

88111
{{< codenew file="admin/resource/memory-defaults-pod.yaml" >}}
89112

@@ -106,7 +129,7 @@ kubectl get pod default-mem-demo --output=yaml --namespace=default-mem-example
106129
```
107130

108131
<!--
109-
The output shows that the Pod's Container has a memory request of 256 MiB and
132+
The output shows that the Pod's container has a memory request of 256 MiB and
110133
a memory limit of 512 MiB. These are the default values specified by the LimitRange.
111134
-->
112135
输出内容显示该 Pod 的容器有 256 MiB 的内存请求和 512 MiB 的内存限制。
@@ -134,14 +157,14 @@ kubectl delete pod default-mem-demo --namespace=default-mem-example
134157
```
135158

136159
<!--
137-
## What if you specify a Container's limit, but not its request?
160+
## What if you specify a container's limit, but not its request?
138161
139-
Here's the configuration file for a Pod that has one Container. The Container
162+
Here's a manifest for a Pod that has one container. The container
140163
specifies a memory limit, but not a request:
141164
-->
142165
## 声明容器的限制而不声明它的请求会怎么样?
143166

144-
这里给出了包含一个容器的 Pod 的配置文件。该容器声明了内存限制,而没有声明内存请求
167+
以下为只包含一个容器的 Pod 的清单。该容器声明了内存限制,而没有声明内存请求
145168

146169
{{< codenew file="admin/resource/memory-defaults-pod-2.yaml" >}}
147170

@@ -164,8 +187,8 @@ kubectl get pod default-mem-demo-2 --output=yaml --namespace=default-mem-example
164187
```
165188

166189
<!--
167-
The output shows that the Container's memory request is set to match its memory limit.
168-
Notice that the Container was not assigned the default memory request value of 256Mi.
190+
The output shows that the container's memory request is set to match its memory limit.
191+
Notice that the container was not assigned the default memory request value of 256Mi.
169192
-->
170193
输出结果显示容器的内存请求被设置为它的内存限制相同的值。注意该容器没有被指定默认的内存请求值 256MiB。
171194

@@ -178,15 +201,15 @@ resources:
178201
```
179202

180203
<!--
181-
## What if you specify a Container's request, but not its limit?
204+
## What if you specify a container's request, but not its limit?
182205
-->
183206
## 声明容器的内存请求而不声明内存限制会怎么样?
184207

185208
<!--
186-
Here's the configuration file for a Pod that has one Container. The Container
209+
Here's a manifest for a Pod that has one container. The container
187210
specifies a memory request, but not a limit:
188211
-->
189-
这里给出了一个包含一个容器的 Pod 的配置文件。该容器声明了内存请求,但没有内存限制:
212+
以下为只包含一个容器的 Pod 的清单。该容器声明了内存请求,但没有内存限制:
190213

191214
{{< codenew file="admin/resource/memory-defaults-pod-3.yaml" >}}
192215

@@ -209,12 +232,12 @@ kubectl get pod default-mem-demo-3 --output=yaml --namespace=default-mem-example
209232
```
210233

211234
<!--
212-
The output shows that the Container's memory request is set to the value specified in the
213-
Container's configuration file. The Container's memory limit is set to 512Mi, which is the
214-
default memory limit for the namespace.
235+
The output shows that the container's memory request is set to the value specified in the
236+
container's manifest. The container is limited to use no more than 512MiB of
237+
memory, which matches the default memory limit for the namespace.
215238
-->
216-
输出结果显示该容器的内存请求被设置为了容器配置文件中声明的数值
217-
容器的内存限制被设置为 512MiB,即命名空间的默认内存限制
239+
输出结果显示所创建的 Pod 中,容器的内存请求为 Pod 清单中声明的值
240+
然而同一容器的内存限制被设置为 512MiB,此值是该命名空间的默认内存限制值
218241

219242
```
220243
resources:
@@ -227,27 +250,45 @@ resources:
227250
<!--
228251
## Motivation for default memory limits and requests
229252
230-
If your namespace has a resource quota,
253+
If your namespace has a memory {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
254+
configured,
231255
it is helpful to have a default value in place for memory limit.
232-
Here are two of the restrictions that a resource quota imposes on a namespace:
256+
Here are three of the restrictions that a resource quota imposes on a namespace:
257+
258+
* For every Pod that runs in the namespace, the Pod and each of its containers must have a memory limit.
259+
(If you specify a memory limit for every container in a Pod, Kubernetes can infer the Pod-level memory
260+
limit by adding up the limits for its containers).
261+
* Memory limits apply a resource reservation on the node where the Pod in question is scheduled.
262+
The total amount of memory reserved for all Pods in the namespace must not exceed a specified limit.
263+
* The total amount of memory actually used by all Pods in the namespace must also not exceed a specified limit.
233264
-->
234265
## 设置默认内存限制和请求的动机
235266

236-
如果你的命名空间有资源配额,那么默认内存限制是很有帮助的。
237-
下面是一个例子,通过资源配额为命名空间设置两项约束:
267+
如果你的命名空间设置了内存 {{< glossary_tooltip text="资源配额" term_id="resource-quota" >}},
268+
那么为内存限制设置一个默认值会很有帮助。
269+
以下是内存资源配额对命名空间的施加的三条限制:
238270

239-
<!--
240-
* Every Container that runs in the namespace must have its own memory limit.
241-
* The total amount of memory used by all Containers in the namespace must not exceed a specified limit.
242-
-->
243-
* 运行在命名空间中的每个容器必须有自己的内存限制。
244-
* 命名空间中所有容器的内存使用量之和不能超过声明的限制值。
271+
* 命名空间中运行的每个 Pod 中的容器都必须有内存限制。
272+
(如果为 Pod 中的每个容器声明了内存限制,
273+
Kubernetes 可以通过将其容器的内存限制相加推断出 Pod 级别的内存限制)。
274+
275+
* 内存限制用来在 Pod 被调度到的节点上执行资源预留。
276+
预留给命名空间中所有 Pod 使用的内存总量不能超过规定的限制。
277+
278+
* 命名空间中所有 Pod 实际使用的内存总量也不能超过规定的限制。
245279

246280
<!--
247-
If a Container does not specify its own memory limit, it is given the default limit, and then
248-
it can be allowed to run in a namespace that is restricted by a quota.
281+
When you add a LimitRange:
282+
283+
If any Pod in that namespace that includes a container does not specify its own memory limit,
284+
the control plane applies the default memory limit to that container, and the Pod can be
285+
allowed to run in a namespace that is restricted by a memory ResourceQuota.
249286
-->
250-
如果一个容器没有声明自己的内存限制,会被指定默认限制,然后它才会被允许在限定了配额的命名空间中运行。
287+
当你添加 LimitRange 时:
288+
289+
如果该命名空间中的任何 Pod 的容器未指定内存限制,
290+
控制面将默认内存限制应用于该容器,
291+
这样 Pod 可以在受到内存 ResourceQuota 限制的命名空间中运行。
251292

252293
<!--
253294
## Clean up

0 commit comments

Comments
 (0)