Skip to content

Commit 86a5120

Browse files
authored
Merge pull request #33779 from TinySong/task-5
[zh] sync tasks/administer-cluster/manage-resources
2 parents 9c6b191 + 177423b commit 86a5120

File tree

4 files changed

+193
-111
lines changed

4 files changed

+193
-111
lines changed

content/zh/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace.md

Lines changed: 83 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,53 @@
22
title: 为命名空间配置 CPU 最小和最大约束
33
content_type: task
44
weight: 40
5+
description: >-
6+
为命名空间定义一个有效的 CPU 资源限制范围,使得在该命名空间中所有新建 Pod 的 CPU 资源是在你所设置的范围内。
57
---
68

79
<!--
810
title: Configure Minimum and Maximum CPU Constraints for a Namespace
911
content_type: task
1012
weight: 40
13+
description: >-
14+
Define a range of valid CPU resource limits for a namespace, so that every new Pod
15+
in that namespace falls within the range you configure.
1116
-->
1217

1318
<!-- overview -->
1419

1520
<!--
16-
This page shows how to set minimum and maximum values for the CPU resources used by Containers
17-
and Pods in a namespace. You specify minimum and maximum CPU values in a
18-
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
21+
This page shows how to set minimum and maximum values for the CPU resources used by containers
22+
and Pods in a {{< glossary_tooltip text="namespace" term_id="namespace" >}}. You specify minimum
23+
and maximum CPU values in a
24+
[LimitRange](/docs/reference/kubernetes-api/policy-resources/limit-range-v1/)
1925
object. If a Pod does not meet the constraints imposed by the LimitRange, it cannot be created
2026
in the namespace.
2127
-->
22-
本页介绍如何为命名空间中容器和 Pod 使用的 CPU 资源设置最小和最大值。
28+
本页介绍如何为{{< glossary_tooltip text="命名空间" term_id="namespace" >}}中的容器和 Pod
29+
设置其所使用的 CPU 资源的最小和最大值。
2330
你可以通过
24-
[LimitRange](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#limitrange-v1-core)
25-
对象声明 CPU 的最小和最大值. 如果 Pod 不能满足 LimitRange 的限制,它就不能在命名空间中创建。
31+
[LimitRange](/docs/reference/kubernetes-api/policy-resources/limit-range-v1/)
32+
对象声明 CPU 的最小和最大值.
33+
如果 Pod 不能满足 LimitRange 的限制,就无法在该命名空间中被创建。
2634

2735
## {{% heading "prerequisites" %}}
2836

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

3139
<!--
32-
Your cluster must have at least 1 CPU available for use to run the task examples.
40+
You must have access to create namespaces in your cluster.
41+
42+
Each node in your cluster must have at least 1.0 CPU available for Pods.
43+
See [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
44+
to learn what Kubernetes means by “1 CPU”.
3345
-->
34-
你的集群中每个节点至少要有 1 个 CPU 可用才能运行本任务示例。
46+
在你的集群里你必须要有创建命名空间的权限。
47+
48+
集群中的每个节点都必须至少有 1.0 个 CPU 可供 Pod 使用。
49+
50+
请阅读 [CPU 的含义](/zh/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
51+
理解 "1 CPU" 在 Kubernetes 中的含义。
3552

3653
<!-- steps -->
3754

@@ -52,11 +69,11 @@ kubectl create namespace constraints-cpu-example
5269
<!--
5370
## Create a LimitRange and a Pod
5471
55-
Here's the configuration file for a LimitRange:
72+
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}:
5673
-->
5774
## 创建 LimitRange 和 Pod
5875

59-
这里给出了 LimitRange 的配置文件
76+
以下为 {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}} 的示例清单
6077

6178
{{< codenew file="admin/resource/cpu-constraints.yaml" >}}
6279

@@ -100,24 +117,25 @@ limits:
100117
```
101118
102119
<!--
103-
Now whenever a Container is created in the constraints-cpu-example namespace, Kubernetes
104-
performs these steps:
120+
Now whenever you create a Pod in the constraints-cpu-example namespace (or some other client
121+
of the Kubernetes API creates an equivalent Pod), Kubernetes performs these steps:
105122
106-
* If the Container does not specify its own CPU request and limit, assign the default
107-
CPU request and limit to the Container.
123+
* If any container in that Pod does not specify its own CPU request and limit, the control plane
124+
assigns the default CPU request and limit to that container.
108125
109-
* Verify that the Container specifies a CPU request that is greater than or equal to 200 millicpu.
126+
* Verify that every container in that Pod specifies a CPU request that is greater than or equal to 200 millicpu.
110127
111-
* Verify that the Container specifies a CPU limit that is less than or equal to 800 millicpu.
128+
* Verify that every container in that Pod specifies a CPU limit that is less than or equal to 800 millicpu.
112129
-->
113130
114-
现在不管什么时候在 constraints-cpu-example 命名空间中创建容器,Kubernetes 都会执行下面这些步骤:
131+
现在,每当你在 constraints-mem-example 命名空间中创建 Pod 时,或者某些其他的
132+
Kubernetes API 客户端创建了等价的 Pod 时,Kubernetes 就会执行下面的步骤:
115133
116-
* 如果容器没有声明自己的 CPU 请求和限制,将为容器指定默认 CPU 请求和限制。
134+
* 如果 Pod 中的任何容器未声明自己的 CPU 请求和限制,控制面将为该容器设置默认的 CPU 请求和限制。
117135
118-
* 核查容器声明的 CPU 请求确保其大于或者等于 200 millicpu。
136+
* 确保该 Pod 中的每个容器的 CPU 请求至少 200 millicpu。
119137
120-
* 核查容器声明的 CPU 限制确保其小于或者等于 800 millicpu。
138+
* 确保该 Pod 中每个容器 CPU 请求不大于 800 millicpu。
121139
122140
<!--
123141
When creating a `LimitRange` object, you can specify limits on huge-pages
@@ -130,29 +148,29 @@ on these resources, the two values must be the same.
130148
{{< /note >}}
131149

132150
<!--
133-
Here's the configuration file for a Pod that has one Container. The Container manifest
151+
Here's a manifest for a Pod that has one container. The container manifest
134152
specifies a CPU request of 500 millicpu and a CPU limit of 800 millicpu. These satisfy the
135153
minimum and maximum CPU constraints imposed by the LimitRange.
136154
-->
137-
这里给出了包含一个容器的 Pod 的配置文件
138-
该容器声明了 500 millicpu CPU 请求和 800 millicpu 的 CPU 限制
155+
以下为某个仅包含一个容器的 Pod 的清单
156+
该容器声明了 CPU 请求 500 millicpu CPU 限制 800 millicpu 。
139157
这些参数满足了 LimitRange 对象规定的 CPU 最小和最大限制。
140158

141159
{{< codenew file="admin/resource/cpu-constraints-pod.yaml" >}}
142160

143161
<!--
144162
Create the Pod:
145163
-->
146-
创建Pod
164+
创建 Pod
147165

148166
```shell
149167
kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod.yaml --namespace=constraints-cpu-example
150168
```
151169

152170
<!--
153-
Verify that the Pod's Container is running:
171+
Verify that the Pod is running and that its container is healthy:
154172
-->
155-
确认一下 Pod 中的容器在运行
173+
确认 Pod 正在运行,并且其容器处于健康状态
156174

157175
```shell
158176
kubectl get pod constraints-cpu-demo --namespace=constraints-cpu-example
@@ -168,10 +186,10 @@ kubectl get pod constraints-cpu-demo --output=yaml --namespace=constraints-cpu-e
168186
```
169187

170188
<!--
171-
The output shows that the Container has a CPU request of 500 millicpu and CPU limit
189+
The output shows that the Pod's only container has a CPU request of 500 millicpu and CPU limit
172190
of 800 millicpu. These satisfy the constraints imposed by the LimitRange.
173191
-->
174-
输出结果表明容器的 CPU 请求为 500 millicpu,CPU 限制为 800 millicpu。
192+
输出结果显示该 Pod 的容器的 CPU 请求为 500 millicpu,CPU 限制为 800 millicpu。
175193
这些参数满足 LimitRange 规定的限制范围。
176194

177195
```yaml
@@ -214,10 +232,11 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-2.ya
214232
```
215233

216234
<!--
217-
The output shows that the Pod does not get created, because the Container specifies a CPU limit that is
218-
too large:
235+
The output shows that the Pod does not get created, because it defines an unacceptable container.
236+
That container is not acceptable because it specifies a CPU limit that is too large:
219237
-->
220-
输出结果表明 Pod 没有创建成功,因为容器声明的 CPU 限制太大了:
238+
输出结果表明 Pod 没有创建成功,因为其中定义了一个无法被接受的容器。
239+
该容器之所以无法被接受是因为其中设定了过高的 CPU 限制值:
221240

222241
```
223242
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-2.yaml":
@@ -227,12 +246,12 @@ pods "constraints-cpu-demo-2" is forbidden: maximum cpu usage per Container is 8
227246
<!--
228247
## Attempt to create a Pod that does not meet the minimum CPU request
229248
230-
Here's the configuration file for a Pod that has one Container. The Container specifies a
249+
Here's a manifest for a Pod that has one container. The container specifies a
231250
CPU request of 100 millicpu and a CPU limit of 800 millicpu.
232251
-->
233252
## 尝试创建一个不满足最小 CPU 请求的 Pod
234253
235-
这里给出了包含一个容器的 Pod 的配置文件。该容器声明了100 millicpu的 CPU 请求和800 millicpu的 CPU 限制。
254+
以下为某个只有一个容器的 Pod 的清单。该容器声明了 CPU 请求 100 millicpu 和 CPU 限制 800 millicpu
236255
237256
{{< codenew file="admin/resource/cpu-constraints-pod-3.yaml" >}}
238257
@@ -246,10 +265,12 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-constraints-pod-3.ya
246265
```
247266

248267
<!--
249-
The output shows that the Pod does not get created, because the Container specifies a CPU
250-
request that is too small:
268+
The output shows that the Pod does not get created, because it defines an unacceptable container.
269+
That container is not acceptable because it specifies a CPU request that is lower than the
270+
enforced minimum:
251271
-->
252-
输出结果显示 Pod 没有创建成功,因为容器声明的 CPU 请求太小了:
272+
输出结果显示 Pod 没有创建成功,因为其中定义了一个无法被接受的容器。
273+
该容器无法被接受的原因是其中所设置的 CPU 请求小于最小值的限制:
253274

254275
```
255276
Error from server (Forbidden): error when creating "examples/admin/resource/cpu-constraints-pod-3.yaml":
@@ -259,12 +280,12 @@ pods "constraints-cpu-demo-4" is forbidden: minimum cpu usage per Container is 2
259280
<!--
260281
## Create a Pod that does not specify any CPU request or limit
261282
262-
Here's the configuration file for a Pod that has one Container. The Container does not
263-
specify a CPU request, and it does not specify a CPU limit.
283+
Here's a manifest for a Pod that has one container. The container does not
284+
specify a CPU request, nor does it specify a CPU limit.
264285
-->
265286
## 创建一个没有声明 CPU 请求和 CPU 限制的 Pod
266287

267-
这里给出了包含一个容器的 Pod 的配置文件。该容器没有设定 CPU 请求和 CPU 限制。
288+
以下为一个只有一个容器的 Pod 的清单。该容器没有声明 CPU 请求,也没有声明 CPU 限制。
268289

269290
{{< codenew file="admin/resource/cpu-constraints-pod-4.yaml" >}}
270291

@@ -287,11 +308,14 @@ kubectl get pod constraints-cpu-demo-4 --namespace=constraints-cpu-example --out
287308
```
288309

289310
<!--
290-
The output shows that the Pod's Container has a CPU request of 800 millicpu and a CPU limit of 800 millicpu.
291-
How did the Container get those values?
311+
The output shows that the Pod's single container has a CPU request of 800 millicpu and a
312+
CPU limit of 800 millicpu.
313+
How did that container get those values?
292314
-->
293-
输出结果显示 Pod 的容器有个 800 millicpu 的 CPU 请求和 800 millicpu 的 CPU 限制。
294-
容器是怎样得到那些值的呢?
315+
输出结果显示 Pod 的唯一容器的 CPU 请求为 800 millicpu,CPU 限制为 800 millicpu。
316+
317+
容器是怎样获得这些数值的呢?
318+
295319

296320
```yaml
297321
resources:
@@ -302,26 +326,27 @@ resources:
302326
```
303327
304328
<!--
305-
Because your Container did not specify its own CPU request and limit, it was given the
306-
[default CPU request and limit](/docs/tasks/administer-cluster/cpu-default-namespace/)
307-
from the LimitRange.
329+
Because that container did not specify its own CPU request and limit, the control plane
330+
applied the
331+
[default CPU request and limit](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
332+
from the LimitRange for this namespace.
308333
-->
309-
因为你的 Container 没有声明自己的 CPU 请求和限制,LimitRange 给它指定了
310-
[默认的 CPU 请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
334+
因为这一容器没有声明自己的 CPU 请求和限制,
335+
控制面会根据命名空间中配置 LimitRange
336+
设置[默认的 CPU 请求和限制](/zh/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)。
311337
312338
<!--
313-
At this point, your Container might be running or it might not be running. Recall that a prerequisite
314-
for this task is that your Nodes have at least 1 CPU. If each of your Nodes has only
315-
1 CPU, then there might not be enough allocatable CPU on any Node to accommodate a request
316-
of 800 millicpu. If you happen to be using Nodes with 2 CPU, then you probably have
317-
enough CPU to accommodate the 800 millicpu request.
339+
At this point, your Pod might be running or it might not be running. Recall that a prerequisite for
340+
this task is that your Nodes must have at least 1 CPU available for use. If each of your Nodes has only 1 CPU,
341+
then there might not be enough allocatable CPU on any Node to accommodate a request of 800 millicpu.
342+
If you happen to be using Nodes with 2 CPU, then you probably have enough CPU to accommodate the 800 millicpu request.
318343
319344
Delete your Pod:
320345
-->
321-
此时,你的容器可能运行也可能没有运行
322-
回想一下,本任务的先决条件是你的节点要有 1 个 CPU。
323-
如果你的每个节点仅有 1 CPU,那么可能没有任何一个节点可以满足 800 millicpu 的 CPU 请求
324-
如果你在用的节点恰好有两个 CPU,那么你才可能有足够的 CPU 来满足 800 millicpu 的请求。
346+
此时,你的 Pod 可能已经运行起来也可能没有运行起来
347+
回想一下我们本次任务的先决条件是你的每个节点都至少有 1 CPU。
348+
如果你的每个节点都只有 1 CPU,那将没有一个节点拥有足够的可分配 CPU 来满足 800 millicpu 的请求
349+
如果你在用的节点恰好有 2 CPU,那么有可能有足够的 CPU 来满足 800 millicpu 的请求。
325350
326351
```
327352
kubectl delete pod constraints-cpu-demo-4 --namespace=constraints-cpu-example

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ file for the LimitRange, they were created automatically.
107107
Now whenever you define a Pod within the constraints-mem-example namespace, Kubernetes
108108
performs these steps:
109109
110-
* If any container in that Pod does not specify its own memory request and limit, assign
111-
the default memory request and limit to that container.
110+
* If any container in that Pod does not specify its own memory request and limit,
111+
the control plane assig nthe default memory request and limit to that container.
112112
113113
* Verify that every container in that Pod requests at least 500 MiB of memory.
114114
@@ -121,7 +121,7 @@ minimum and maximum memory constraints imposed by the LimitRange.
121121
-->
122122
现在,每当在 constraints-mem-example 命名空间中创建 Pod 时,Kubernetes 就会执行下面的步骤:
123123

124-
* 如果 Pod 中的任何容器未声明自己的内存请求和限制,将为该容器设置默认的内存请求和限制
124+
* 如果 Pod 中的任何容器未声明自己的内存请求和限制,控制面将为该容器设置默认的内存请求和限制
125125

126126
* 确保该 Pod 中的每个容器的内存请求至少 500 MiB。
127127

0 commit comments

Comments
 (0)