Skip to content

Commit 410d16d

Browse files
authored
Merge pull request #33723 from TinySong/task-4
[zh] sync manage-resources/*.md
2 parents 62ffe74 + 37dd442 commit 410d16d

File tree

2 files changed

+180
-107
lines changed

2 files changed

+180
-107
lines changed

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

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

79
<!--
@@ -12,20 +14,44 @@ weight: 20
1214

1315
<!-- overview -->
1416
<!--
15-
This page shows how to configure default CPU requests and limits for a namespace.
16-
A Kubernetes cluster can be divided into namespaces. If a Container is created in a namespace
17-
that has a default CPU limit, and the Container does not specify its own CPU limit, then
18-
the Container is assigned the default CPU limit. Kubernetes assigns a default CPU request
19-
under certain conditions that are explained later in this topic.
17+
This page shows how to configure default CPU requests and limits for a
18+
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
19+
20+
A Kubernetes cluster can be divided into namespaces. If you create a Pod within a
21+
namespace that has a default CPU
22+
[limit](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits), and any container in that Pod does not specify
23+
its own CPU limit, then the
24+
{{< glossary_tooltip text="control plane" term_id="control-plane" >}} assigns the default
25+
CPU limit to that container.
26+
27+
Kubernetes assigns a default CPU
28+
[request](/docs/concepts/configuration/manage-resources-containers/#requests-and-limits),
29+
but only under certain conditions that are explained later in this page.
30+
2031
-->
21-
本章介绍怎样为命名空间配置默认的 CPU 请求和限制。
22-
一个 Kubernetes 集群可被划分为多个命名空间。如果在配置了 CPU 限制的命名空间创建容器,
23-
并且该容器没有声明自己的 CPU 限制,那么这个容器会被指定默认的 CPU 限制。
24-
Kubernetes 在一些特定情况还会指定 CPU 请求,本文后续章节将会对其进行解释。
32+
本章介绍如何为{{< glossary_tooltip text="命名空间" term_id="namespace" >}}配置默认的 CPU 请求和限制。
33+
34+
一个 Kubernetes 集群可被划分为多个命名空间。
35+
如果你在具有默认 CPU[限制](/zh/docs/concepts/configuration/manage-resources-containers/#requests-and-limits)
36+
的命名空间内创建一个 Pod,并且这个 Pod 中任何容器都没有声明自己的 CPU 限制,
37+
那么{{< glossary_tooltip text="控制面" term_id="control-plane" >}}会为容器设定默认的 CPU 限制。
38+
39+
Kubernetes 在一些特定情况还可以设置默认的 CPU 请求,本文后续章节将会对其进行解释。
2540

2641
## {{% heading "prerequisites" %}}
2742

28-
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
43+
{{< include "task-tutorial-prereqs.md" >}}
44+
45+
<!--
46+
You must have access to create namespaces in your cluster.
47+
48+
If you're not already familiar with what Kubernetes means by 1.0 CPU,
49+
read [meaning of CPU](/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu).
50+
-->
51+
在你的集群里你必须要有创建命名空间的权限。
52+
53+
如果你还不熟悉 Kubernetes 中 1.0 CPU 的含义,
54+
请阅读 [CPU 的含义](/zh/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)
2955

3056
<!-- steps -->
3157

@@ -46,12 +72,13 @@ kubectl create namespace default-cpu-example
4672
<!--
4773
## Create a LimitRange and a Pod
4874
49-
Here's the configuration file for a LimitRange object. The configuration specifies
50-
a default CPU request and a default CPU limit.
75+
Here's a manifest for an example {{< glossary_tooltip text="LimitRange" term_id="limitrange" >}}.
76+
The manifest specifies a default CPU request and a default CPU limit.
5177
-->
5278
## 创建 LimitRange 和 Pod
5379

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

5683
{{< codenew file="admin/resource/cpu-defaults.yaml" >}}
5784

@@ -65,18 +92,19 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults.yaml --name
6592
```
6693

6794
<!--
68-
Now if a Container is created in the default-cpu-example namespace, and the
69-
Container does not specify its own values for CPU request and CPU limit,
70-
the Container is given a default CPU request of 0.5 and a default
95+
Now if you create a Pod in the default-cpu-example namespace, and any container
96+
in that Pod does not specify its own values for CPU request and CPU limit,
97+
then the control plane applies default values: a CPU request of 0.5 and a default
7198
CPU limit of 1.
7299
73-
Here's the configuration file for a Pod that has one Container. The Container
100+
Here's a manifest for a Pod that has one container. The container
74101
does not specify a CPU request and limit.
75102
-->
76-
现在如果在 default-cpu-example 命名空间创建一个容器,该容器没有声明自己的 CPU 请求和限制时,
77-
将会给它指定默认的 CPU 请求0.5和默认的 CPU 限制值1.
103+
现在如果你在 default-cpu-example 命名空间中创建一个 Pod,
104+
并且该 Pod 中所有容器都没有声明自己的 CPU 请求和 CPU 限制,
105+
控制面会将 CPU 的默认请求值 0.5 和默认限制值 1 应用到 Pod 上。
78106

79-
这里给出了包含一个容器的 Pod 的配置文件。该容器没有声明 CPU 请求和限制。
107+
以下为只包含一个容器的 Pod 的清单。该容器没有声明 CPU 请求和限制。
80108

81109
{{< codenew file="admin/resource/cpu-defaults-pod.yaml" >}}
82110

@@ -99,10 +127,12 @@ kubectl get pod default-cpu-demo --output=yaml --namespace=default-cpu-example
99127
```
100128

101129
<!--
102-
The output shows that the Pod's Container has a CPU request of 500 millicpus and
103-
a CPU limit of 1 cpu. These are the default values specified by the LimitRange.
130+
The output shows that the Pod's only container has a CPU request of 500m `cpu`
131+
(which you can read as “500 millicpu”), and a CPU limit of 1 `cpu`.
132+
These are the default values specified by the LimitRange.
104133
-->
105-
输出显示该 Pod 的容器有一个500 millicpus的 CPU 请求和一个1 cpu的 CPU 限制。这些是 LimitRange 声明的默认值。
134+
输出显示该 Pod 的唯一的容器有 500m `cpu` 的 CPU 请求和 1 `cpu` 的 CPU 限制。
135+
这些是 LimitRange 声明的默认值。
106136

107137
```shell
108138
containers:
@@ -117,14 +147,14 @@ containers:
117147
```
118148

119149
<!--
120-
## What if you specify a Container's limit, but not its request?
150+
## What if you specify a container's limit, but not its request?
121151
122-
Here's the configuration file for a Pod that has one Container. The Container
152+
Here's a manifest for a Pod that has one container. The container
123153
specifies a CPU limit, but not a request:
124154
-->
125155
## 你只声明容器的限制,而不声明请求会怎么样?
126156

127-
这是包含一个容器的 Pod 的配置文件。该容器声明了 CPU 限制,而没有声明 CPU 请求。
157+
以下为只包含一个容器的 Pod 的清单。该容器声明了 CPU 限制,而没有声明 CPU 请求。
128158

129159
{{< codenew file="admin/resource/cpu-defaults-pod-2.yaml" >}}
130160

@@ -138,19 +168,20 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-2.yaml
138168
```
139169

140170
<!--
141-
View the Pod specification:
171+
View the [specification](/docs/concepts/overview/working-with-objects/kubernetes-objects/#object-spec-and-status)
172+
of the Pod that you created:
142173
-->
143-
查看 Pod 的声明
174+
查看你所创建的 Pod [规约](/zh/docs/concepts/overview/working-with-objects/kubernetes-objects/#object-spec-and-status)
144175

145176
```
146177
kubectl get pod default-cpu-demo-2 --output=yaml --namespace=default-cpu-example
147178
```
148179

149180
<!--
150181
The output shows that the Container's CPU request is set to match its CPU limit.
151-
Notice that the Container was not assigned the default CPU request value of 0.5 cpu.
182+
Notice that the container was not assigned the default CPU request value of 0.5 `cpu`:
152183
-->
153-
输出显示该容器的 CPU 请求和 CPU 限制设置相同。注意该容器没有被指定默认的 CPU 请求值0.5 cpu
184+
输出显示该容器的 CPU 请求和 CPU 限制设置相同。注意该容器没有被指定默认的 CPU 请求值 0.5 `cpu`
154185

155186
```
156187
resources:
@@ -161,14 +192,14 @@ resources:
161192
```
162193

163194
<!--
164-
## What if you specify a Container's request, but not its limit?
195+
## What if you specify a container's request, but not its limit?
165196
166-
Here's the configuration file for a Pod that has one Container. The Container
197+
Here's an example manifest for a Pod that has one container. The container
167198
specifies a CPU request, but not a limit:
168199
-->
169200
## 你只声明容器的请求,而不声明它的限制会怎么样?
170201

171-
这里给出了包含一个容器的 Pod 的配置文件。该容器声明了 CPU 请求,而没有声明 CPU 限制。
202+
这里给出了包含一个容器的 Pod 的示例清单。该容器声明了 CPU 请求,而没有声明 CPU 限制。
172203

173204
{{< codenew file="admin/resource/cpu-defaults-pod-3.yaml" >}}
174205

@@ -182,21 +213,22 @@ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-3.yaml
182213
```
183214

184215
<!--
185-
View the Pod specification:
216+
View the specification of the Pod that you created:
186217
-->
187-
查看 Pod 的规约
218+
查看所你创建的 Pod 的规约:
188219

189220
```
190221
kubectl get pod default-cpu-demo-3 --output=yaml --namespace=default-cpu-example
191222
```
192223

193224
<!--
194-
The output shows that the Container's CPU request is set to the value specified in the
195-
Container's configuration file. The Container's CPU limit is set to 1 cpu, which is the
196-
default CPU limit for the namespace.
225+
The output shows that the container's CPU request is set to the value you specified at
226+
the time you created the Pod (in other words: it matches the manifest).
227+
However, the same container's CPU limit is set to 1 `cpu`, which is the default CPU limit
228+
for that namespace.
197229
-->
198-
结果显示该容器的 CPU 请求被设置为容器配置文件中声明的数值
199-
容器的CPU限制被设置为 1 CPU,即该命名空间的默认 CPU 限制值。
230+
输出显示你所创建的 Pod 中,容器的 CPU 请求为 Pod 清单中声明的值
231+
然而同一容器的 CPU 限制被设置为 1 `cpu`,此值是该命名空间的默认 CPU 限制值。
200232

201233
```
202234
resources:
@@ -209,27 +241,41 @@ resources:
209241
<!--
210242
## Motivation for default CPU limits and requests
211243
212-
If your namespace has a
213-
[resource quota](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/),
244+
If your namespace has a CPU {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
245+
configured,
214246
it is helpful to have a default value in place for CPU limit.
215-
Here are two of the restrictions that a resource quota imposes on a namespace:
247+
Here are two of the restrictions that a CPU resource quota imposes on a namespace:
216248
217-
* Every Container that runs in the namespace must have its own CPU limit.
218-
* The total amount of CPU used by all Containers in the namespace must not exceed a specified limit.
249+
* For every Pod that runs in the namespace, each of its containers must have a CPU limit.
250+
* CPU request apply a resource reservation on the node where the Pod in question is scheduled.
251+
The total amount of CPU that is reserved for use by all Pods in the namespace must not
252+
exceed a specified limit.
219253
220-
If a Container does not specify its own CPU limit, it is given the default limit, and then
221-
it can be allowed to run in a namespace that is restricted by a quota.
222254
-->
223255
## 默认 CPU 限制和请求的动机
224256

225-
如果你的命名空间有一个
226-
[资源配额](/zh/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
227-
那么有一个默认的 CPU 限制是有帮助的。这里有资源配额强加给命名空间的两条限制:
257+
如果你的命名空间设置了 CPU {{< glossary_tooltip text="资源配额" term_id="resource-quota" >}},
258+
为 CPU 限制设置一个默认值会很有帮助。
259+
以下是 CPU 资源配额对命名空间的施加的两条限制:
260+
261+
* 命名空间中运行的每个 Pod 中的容器都必须有 CPU 限制。
262+
263+
* CPU 限制用来在 Pod 被调度到的节点上执行资源预留。
228264

229-
* 命名空间中运行的每个容器必须有自己的 CPU 限制。
230-
* 命名空间中所有容器使用的 CPU 总和不能超过一个声明值。
265+
预留给命名空间中所有 Pod 使用的 CPU 总量不能超过规定的限制。
266+
267+
<!--
268+
When you add a LimitRange:
269+
270+
If any Pod in that namespace that includes a container does not specify its own CPU limit,
271+
the control plane applies the default CPU limit to that container, and the Pod can be
272+
allowed to run in a namespace that is restricted by a CPU ResourceQuota.
273+
-->
274+
当你添加 LimitRange 时:
231275

232-
如果容器没有声明自己的 CPU 限制,将会给它一个默认限制,这样它就能被允许运行在一个有配额限制的命名空间中。
276+
如果该命名空间中的任何 Pod 的容器未指定 CPU 限制,
277+
控制面将默认 CPU 限制应用于该容器,
278+
这样 Pod 可以在受到 CPU ResourceQuota 限制的命名空间中运行。
233279

234280
<!--
235281
## Clean up

0 commit comments

Comments
 (0)