@@ -14,39 +14,46 @@ weight: 30
14
14
15
15
<!--
16
16
This page shows how to configure Pods so that they will be assigned particular
17
- Quality of Service (QoS) classes. Kubernetes uses QoS classes to make decisions about
18
- scheduling and evicting Pods.
17
+ {{< glossary_tooltip text=" Quality of Service (QoS) classes" term_id="qos-class" >}}.
18
+ Kubernetes uses QoS classes to make decisions about evicting Pods when Node resources are exceeded .
19
19
-->
20
- 本页介绍怎样配置 Pod 让其获得特定的服务质量(QoS)类。Kubernetes 使用 QoS 类来决定 Pod 的调度和驱逐策略。
20
+ 本页介绍怎样配置 Pod 以让其归属于特定的
21
+ {{< glossary_tooltip text="服务质量类(Quality of Service class,QoS class)" term_id="qos-class" >}}.
22
+ Kubernetes 在 Node 资源不足时使用 QoS 类来就驱逐 Pod 作出决定。
21
23
22
- ## {{% heading "prerequisites" %}}
24
+ <!--
25
+ When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:
23
26
24
- {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
27
+ * [Guaranteed](/docs/concepts/workloads/pods/pod-qos/#guaranteed)
28
+ * [Burstable](/docs/concepts/workloads/pods/pod-qos/#burstable)
29
+ * [BestEffort](/docs/concepts/workloads/pods/pod-qos/#besteffort)
30
+ -->
31
+ Kubernetes 创建 Pod 时,会将如下 QoS 类之一设置到 Pod 上:
25
32
26
- <!-- steps -->
33
+ * [ Guaranteed] ( /zh-cn/docs/concepts/workloads/pods/pod-qos/#guaranteed )
34
+ * [ Burstable] ( /zh-cn/docs/concepts/workloads/pods/pod-qos/#burstable )
35
+ * [ BestEffort] ( /zh-cn/docs/concepts/workloads/pods/pod-qos/#besteffort )
27
36
28
- <!--
29
- ## QoS classes
37
+ ## {{% heading "prerequisites" %}}
30
38
31
- When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:
32
- -->
33
- ## QoS 类 {#qos-classes}
39
+ {{< include "task-tutorial-prereqs.md" >}}
34
40
35
- Kubernetes 创建 Pod 时就给它指定了下列一种 QoS 类:
41
+ <!--
42
+ You also need to be able to create and delete namespaces.
43
+ -->
44
+ 你还需要能够创建和删除名字空间。
36
45
37
- * Guaranteed
38
- * Burstable
39
- * BestEffort
46
+ <!-- steps -->
40
47
41
48
<!--
42
49
## Create a namespace
43
50
44
51
Create a namespace so that the resources you create in this exercise are
45
52
isolated from the rest of your cluster.
46
53
-->
47
- ## 创建命名空间 {#create-a-namespace}
54
+ ## 创建名字空间 {#create-a-namespace}
48
55
49
- 创建一个命名空间 ,以便将本练习所创建的资源与集群的其余资源相隔离。
56
+ 创建一个名字空间 ,以便将本练习所创建的资源与集群的其余资源相隔离。
50
57
51
58
``` shell
52
59
kubectl create namespace qos-example
@@ -62,10 +69,6 @@ For a Pod to be given a QoS class of Guaranteed:
62
69
* Every Container in the Pod must have a CPU limit and a CPU request.
63
70
* For every Container in the Pod, the CPU limit must equal the CPU request.
64
71
65
- These restrictions apply to init containers and app containers equally.
66
-
67
- Here is the configuration file for a Pod that has one Container. The Container has a memory limit and a
68
- memory request, both equal to 200 MiB. The Container has a CPU limit and a CPU request, both equal to 700 milliCPU:
69
72
-->
70
73
## 创建一个 QoS 类为 Guaranteed 的 Pod {#create-a-pod-that-gets-assigned-a-qos-class-of-guaranteed}
71
74
@@ -76,11 +79,21 @@ memory request, both equal to 200 MiB. The Container has a CPU limit and a CPU r
76
79
* Pod 中的每个容器都必须指定 CPU 限制和 CPU 请求。
77
80
* 对于 Pod 中的每个容器,CPU 限制必须等于 CPU 请求。
78
81
82
+ <!--
83
+ These restrictions apply to init containers and app containers equally.
84
+ [Ephemeral containers](/docs/concepts/workloads/pods/ephemeral-containers/)
85
+ cannot define resources so these restrictions do not apply.
86
+
87
+ Here is a manifest for a Pod that has one Container. The Container has a memory limit and a
88
+ memory request, both equal to 200 MiB. The Container has a CPU limit and a CPU request, both equal to 700 milliCPU:
89
+ -->
90
+
79
91
这些限制同样适用于初始化容器和应用程序容器。
92
+ [ 临时容器(Ephemeral Container)] ( /zh-cn/docs/concepts/workloads/pods/ephemeral-containers/ )
93
+ 无法定义资源,因此不受这些约束限制。
80
94
81
- 下面是包含一个容器的 Pod 配置文件。
82
- 该容器设置了内存请求和内存限制,值都是 200 MiB。
83
- 该容器设置了 CPU 请求和 CPU 限制,值都是 700 milliCPU:
95
+ 下面是包含一个 Container 的 Pod 清单。该 Container 设置了内存请求和内存限制,值都是 200 MiB。
96
+ 该 Container 设置了 CPU 请求和 CPU 限制,值都是 700 milliCPU:
84
97
85
98
{{< codenew file="pods/qos/qos-pod.yaml" >}}
86
99
@@ -133,10 +146,16 @@ automatically assigns a memory request that matches the limit. Similarly, if a C
133
146
CPU limit, but does not specify a CPU request, Kubernetes automatically assigns a CPU request that matches
134
147
the limit.
135
148
-->
136
- 如果容器指定了自己的内存限制,但没有指定内存请求,Kubernetes 会自动为它指定与内存限制匹配的内存请求。
137
- 同样,如果容器指定了自己的 CPU 限制,但没有指定 CPU 请求,Kubernetes 会自动为它指定与 CPU 限制匹配的 CPU 请求。
149
+ 如果某 Container 指定了自己的内存限制,但没有指定内存请求,Kubernetes
150
+ 会自动为它指定与内存限制相等的内存请求。同样,如果容器指定了自己的 CPU 限制,
151
+ 但没有指定 CPU 请求,Kubernetes 会自动为它指定与 CPU 限制相等的 CPU 请求。
138
152
{{< /note >}}
139
153
154
+ <!--
155
+ #### Clean up {#clean-up-guaranteed}
156
+ -->
157
+ #### 清理 {#clean-up-guaranteed}
158
+
140
159
<!--
141
160
Delete your Pod:
142
161
-->
@@ -149,23 +168,23 @@ kubectl delete pod qos-demo --namespace=qos-example
149
168
<!--
150
169
## Create a Pod that gets assigned a QoS class of Burstable
151
170
152
- A Pod is given a QoS class of Burstable if:
171
+ A Pod is given a QoS class of ` Burstable` if:
153
172
154
- * The Pod does not meet the criteria for QoS class Guaranteed.
173
+ * The Pod does not meet the criteria for QoS class ` Guaranteed` .
155
174
* At least one Container in the Pod has a memory or CPU request or limit.
156
175
157
- Here is the configuration file for a Pod that has one Container. The Container has a memory limit of 200 MiB
176
+ Here is a manifest for a Pod that has one Container. The Container has a memory limit of 200 MiB
158
177
and a memory request of 100 MiB.
159
178
-->
160
179
## 创建一个 QoS 类为 Burstable 的 Pod {#create-a-pod-that-gets-assigned-a-qos-class-of-burstable}
161
180
162
- 如果满足下面条件,将会指定 Pod 的 QoS 类为 Burstable:
181
+ 如果满足下面条件,Kubernetes 将会指定 Pod 的 QoS 类为 ` Burstable ` :
163
182
164
- * Pod 不符合 Guaranteed QoS 类的标准。
165
- * Pod 中至少一个容器具有内存或 CPU 的请求或限制。
183
+ * Pod 不符合 ` Guaranteed ` QoS 类的标准。
184
+ * Pod 中至少一个 Container 具有内存或 CPU 的请求或限制。
166
185
167
- 下面是包含一个容器的 Pod 配置文件。
168
- 该容器设置了内存限制 200 MiB 和内存请求 100 MiB。
186
+ 下面是包含一个 Container 的 Pod 清单。该 Container 设置的内存限制为 200 MiB,
187
+ 内存请求为 100 MiB。
169
188
170
189
{{< codenew file="pods/qos/qos-pod-2.yaml" >}}
171
190
@@ -188,9 +207,9 @@ kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml
188
207
```
189
208
190
209
<!--
191
- The output shows that Kubernetes gave the Pod a QoS class of Burstable.
210
+ The output shows that Kubernetes gave the Pod a QoS class of ` Burstable`:
192
211
-->
193
- 结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable。
212
+ 结果表明 Kubernetes 为 Pod 配置的 QoS 类为 ` Burstable ` 。
194
213
195
214
``` yaml
196
215
spec :
@@ -208,6 +227,11 @@ status:
208
227
qosClass : Burstable
209
228
` ` `
210
229
230
+ <!--
231
+ #### Clean up {#clean-up-burstable}
232
+ -->
233
+ #### 清理 {#clean-up-burstable}
234
+
211
235
<!--
212
236
Delete your Pod:
213
237
-->
@@ -220,18 +244,17 @@ kubectl delete pod qos-demo-2 --namespace=qos-example
220
244
<!--
221
245
## Create a Pod that gets assigned a QoS class of BestEffort
222
246
223
- For a Pod to be given a QoS class of BestEffort, the Containers in the Pod must not
247
+ For a Pod to be given a QoS class of ` BestEffort` , the Containers in the Pod must not
224
248
have any memory or CPU limits or requests.
225
249
226
250
Here is the configuration file for a Pod that has one Container. The Container has no memory or CPU
227
251
limits or requests:
228
252
-->
229
253
## 创建一个 QoS 类为 BestEffort 的 Pod {#create-a-pod-that-gets-assigned-a-qos-class-of-besteffort}
230
254
231
- 对于 QoS 类为 BestEffort 的 Pod,Pod 中的容器必须没有设置内存和 CPU 限制或请求。
255
+ 对于 QoS 类为 ` BestEffort ` 的 Pod,Pod 中的 Container 必须没有设置内存和 CPU 限制或请求。
232
256
233
- 下面是包含一个容器的 Pod 配置文件。
234
- 该容器没有设置内存和 CPU 限制或请求。
257
+ 下面是包含一个 Container 的 Pod 清单。该 Container 没有设置内存和 CPU 限制或请求。
235
258
236
259
{{< codenew file="pods/qos/qos-pod-3.yaml" >}}
237
260
@@ -254,9 +277,9 @@ kubectl get pod qos-demo-3 --namespace=qos-example --output=yaml
254
277
```
255
278
256
279
<!--
257
- The output shows that Kubernetes gave the Pod a QoS class of BestEffort.
280
+ The output shows that Kubernetes gave the Pod a QoS class of ` BestEffort`:
258
281
-->
259
- 结果表明 Kubernetes 为 Pod 配置的 QoS 类为 BestEffort。
282
+ 结果表明 Kubernetes 为 Pod 配置的 QoS 类为 ` BestEffort ` 。
260
283
261
284
``` yaml
262
285
spec :
@@ -268,6 +291,11 @@ status:
268
291
qosClass : BestEffort
269
292
` ` `
270
293
294
+ <!--
295
+ #### Clean up {#clean-up-besteffort}
296
+ -->
297
+ #### 清理 {#clean-up-besteffort}
298
+
271
299
<!--
272
300
Delete your Pod:
273
301
-->
@@ -285,20 +313,19 @@ request of 200 MiB. The other Container does not specify any requests or limits.
285
313
-->
286
314
## 创建包含两个容器的 Pod {#create-a-pod-that-has-two-containers}
287
315
288
- 下面是包含两个容器的 Pod 配置文件。
289
- 一个容器指定了内存请求 200 MiB。
290
- 另外一个容器没有指定任何请求和限制。
316
+ 下面是包含两个 Container 的 Pod 配置文件。一个 Container 指定内存请求为 200 MiB。
317
+ 另外一个 Container 没有指定任何请求或限制。
291
318
292
319
{{< codenew file="pods/qos/qos-pod-4.yaml" >}}
293
320
294
321
<!--
295
- Notice that this Pod meets the criteria for QoS class Burstable. That is, it does not meet the
322
+ Notice that this Pod meets the criteria for QoS class ` Burstable` . That is, it does not meet the
296
323
criteria for QoS class Guaranteed, and one of its Containers has a memory request.
297
324
298
325
Create the Pod:
299
326
-->
300
- 注意此 Pod 满足 Burstable QoS 类的标准。
301
- 也就是说它不满足 Guaranteed QoS 类标准,因为它的一个容器设有内存请求 。
327
+ 注意此 Pod 满足 ` Burstable ` QoS 类的标准。也就是说它不满足 Guaranteed QoS 类标准,
328
+ 因为它的 Container 之一设有内存请求 。
302
329
303
330
创建 Pod:
304
331
@@ -316,9 +343,9 @@ kubectl get pod qos-demo-4 --namespace=qos-example --output=yaml
316
343
```
317
344
318
345
<!--
319
- The output shows that Kubernetes gave the Pod a QoS class of Burstable:
346
+ The output shows that Kubernetes gave the Pod a QoS class of ` Burstable` :
320
347
-->
321
- 结果表明 Kubernetes 为 Pod 配置的 QoS 类为 Burstable:
348
+ 结果表明 Kubernetes 为 Pod 配置的 QoS 类为 ` Burstable ` :
322
349
323
350
``` yaml
324
351
spec :
@@ -336,6 +363,31 @@ status:
336
363
qosClass : Burstable
337
364
` ` `
338
365
366
+ <!--
367
+ ## Retrieve the QoS class for a Pod
368
+
369
+ Rather than see all the fields, you can view just the field you need:
370
+ -->
371
+ ## 检视 Pod 的 QoS 类 {#retrieve-the-qos-class-for-a-pod}
372
+
373
+ <!--
374
+ Rather than see all the fields, you can view just the field you need:
375
+ -->
376
+ 你也可以只查看你所需要的字段,而不是查看所有字段:
377
+
378
+ ` ` ` bash
379
+ kubectl --namespace=qos-example get pod qos-demo-4 -o jsonpath='{ .status.qosClass}{"\n"}'
380
+ ```
381
+
382
+ ``` none
383
+ Burstable
384
+ ```
385
+
386
+ <!--
387
+ ## Clean up
388
+ -->
389
+ ## 清理 {#clean-up}
390
+
339
391
<!--
340
392
Delete your Pod:
341
393
-->
@@ -352,7 +404,7 @@ Delete your namespace:
352
404
-->
353
405
## 环境清理 {#clean-up}
354
406
355
- 删除命名空间 :
407
+ 删除名字空间 :
356
408
357
409
``` shell
358
410
kubectl delete namespace qos-example
@@ -370,44 +422,28 @@ kubectl delete namespace qos-example
370
422
### 应用开发者参考
371
423
372
424
* [ 为 Pod 和容器分配内存资源] ( /zh-cn/docs/tasks/configure-pod-container/assign-memory-resource/ )
373
-
374
425
* [ 为 Pod 和容器分配 CPU 资源] ( /zh-cn/docs/tasks/configure-pod-container/assign-cpu-resource/ )
375
426
376
427
<!--
377
428
### For cluster administrators
378
429
379
430
* [Configure Default Memory Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/)
380
-
381
431
* [Configure Default CPU Requests and Limits for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/)
382
-
383
432
* [Configure Minimum and Maximum Memory Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/)
384
-
385
433
* [Configure Minimum and Maximum CPU Constraints for a Namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/)
386
-
387
434
* [Configure Memory and CPU Quotas for a Namespace](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
388
-
389
435
* [Configure a Pod Quota for a Namespace](/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/)
390
-
391
436
* [Configure Quotas for API Objects](/docs/tasks/administer-cluster/quota-api-object/)
392
-
393
437
* [Control Topology Management policies on a node](/docs/tasks/administer-cluster/topology-manager/)
394
438
-->
395
-
396
439
### 集群管理员参考
397
440
398
- * [ 为命名空间配置默认的内存请求和限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/ )
399
-
400
- * [ 为命名空间配置默认的 CPU 请求和限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/ )
401
-
402
- * [ 为命名空间配置最小和最大内存限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/ )
403
-
404
- * [ 为命名空间配置最小和最大 CPU 限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/ )
405
-
406
- * [ 为命名空间配置内存和 CPU 配额] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/ )
407
-
408
- * [ 为命名空间配置 Pod 配额] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/ )
409
-
441
+ * [ 为名字空间配置默认的内存请求和限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/ )
442
+ * [ 为名字空间配置默认的 CPU 请求和限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/ )
443
+ * [ 为名字空间配置最小和最大内存限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/ )
444
+ * [ 为名字空间配置最小和最大 CPU 限制] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/ )
445
+ * [ 为名字空间配置内存和 CPU 配额] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/ )
446
+ * [ 为名字空间配置 Pod 配额] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/quota-pod-namespace/ )
410
447
* [ 为 API 对象配置配额] ( /zh-cn/docs/tasks/administer-cluster/quota-api-object/ )
411
-
412
448
* [ 控制节点上的拓扑管理策略] ( /zh-cn/docs/tasks/administer-cluster/topology-manager/ )
413
449
0 commit comments