@@ -23,58 +23,115 @@ weight: 20
23
23
When several users or teams share a cluster with a fixed number of nodes,
24
24
there is a concern that one team could use more than its fair share of resources.
25
25
26
- Resource quotas are a tool for administrators to address this concern.
26
+ _Resource quotas_ are a tool for administrators to address this concern.
27
27
-->
28
28
当多个用户或团队共享具有固定节点数目的集群时,人们会担心有人使用超过其基于公平原则所分配到的资源量。
29
29
30
- 资源配额是帮助管理员解决这一问题的工具。
30
+ ** 资源配额** 是帮助管理员解决这一问题的工具。
31
+
32
+ <!--
33
+ A resource quota, defined by a ResourceQuota object, provides constraints that limit
34
+ aggregate resource consumption per {{< glossary_tooltip text="namespace" term_id="namespace" >}}. A ResourceQuota can also
35
+ limit the [quantity of objects that can be created in a namespace](#quota-on-object-count) by API kind, as well as the total
36
+ amount of {{< glossary_tooltip text="infrastructure resources" term_id="infrastructure-resource" >}} that may be consumed by
37
+ API objects found in that namespace.
38
+ -->
39
+ 资源配额,由 ResourceQuota 对象定义,
40
+ 提供了限制每个{{< glossary_tooltip text="命名空间" term_id="namespace" >}}的资源总消耗的约束。
41
+ 资源配额还可以限制在命名空间中可以创建的[ 对象数量] ( #quota-on-object-count ) (按 API 类型计算),
42
+ 以及该命名空间中存在的 API
43
+ 对象可能消耗的{{< glossary_tooltip text="基础设施资源" term_id="infrastructure-resource" >}}的总量。
44
+
45
+ {{< caution >}}
46
+ <!--
47
+ Neither contention nor changes to quota will affect already created resources.
48
+ -->
49
+ 不同的资源争用,或者资源配额的更改不会影响已经创建的资源。
50
+ {{< /caution >}}
31
51
32
52
<!-- body -->
33
53
34
54
<!--
35
- A resource quota, defined by a `ResourceQuota` object, provides constraints that limit
36
- aggregate resource consumption per namespace. It can limit the quantity of objects that can
37
- be created in a namespace by type, as well as the total amount of compute resources that may
38
- be consumed by resources in that namespace.
55
+ ## How Kubernetes ResourceQuotas work
39
56
-->
40
- 资源配额,通过 ` ResourceQuota ` 对象来定义,对每个命名空间的资源消耗总量提供限制。
41
- 它可以限制命名空间中某种类型的对象的总数目上限,也可以限制命名空间中的 Pod 可以使用的计算资源的总上限。
57
+ ## Kubernetes ResourceQuota 的工作原理 {#how-kubernetes-resourcequotas-work}
42
58
43
59
<!--
44
- Resource quotas work like this:
60
+ ResourceQuotas work like this:
45
61
-->
46
- 资源配额的工作方式如下:
62
+ ResourceQuota 的工作方式如下:
63
+
64
+ <!--
65
+ - Different teams work in different namespaces. This separation can be enforced with
66
+ [RBAC](/docs/reference/access-authn-authz/rbac/) or any other [authorization](/docs/reference/access-authn-authz/authorization/)
67
+ mechanism.
68
+
69
+ - A cluster administrator creates at least one ResourceQuota for each namespace.
70
+ - To make sure the enforcement stays enforced, the cluster administrator should also restrict access to delete or update
71
+ that ResourceQuota; for example, by defining a [ValidatingAdmissionPolicy](/docs/reference/access-authn-authz/validating-admission-policy/).
72
+ -->
73
+ - 不同团队在不同的命名空间中工作。
74
+ 这种分离可以通过 [ RBAC] ( /zh-cn/docs/reference/access-authn-authz/rbac/ )
75
+ 或任何其他[ 鉴权] ( /zh-cn/docs/reference/access-authn-authz/authorization/ ) 机制来强制执行。
76
+
77
+ - 集群管理员为每个命名空间创建至少一个 ResourceQuota。
78
+ - 为了确保强制执行不被解除,集群管理员还应限制对删除或更新此 ResourceQuota 的访问;
79
+ 例如,通过定义一个[ 验证准入策略] ( /zh-cn/docs/reference/access-authn-authz/validating-admission-policy/ ) 来实现这点。
47
80
48
81
<!--
49
- - Different teams work in different namespaces. This can be enforced with
50
- [RBAC](/docs/reference/access-authn-authz/rbac/).
51
- - The administrator creates one ResourceQuota for each namespace.
52
82
- Users create resources (pods, services, etc.) in the namespace, and the quota system
53
83
tracks usage to ensure it does not exceed hard resource limits defined in a ResourceQuota.
54
- - If creating or updating a resource violates a quota constraint, the request will fail with HTTP
55
- status code `403 FORBIDDEN` with a message explaining the constraint that would have been violated.
56
- - If quotas are enabled in a namespace for compute resources like `cpu` and `memory`, users must specify
57
- requests or limits for those values; otherwise, the quota system may reject pod creation. Hint: Use
58
- the `LimitRanger` admission controller to force defaults for pods that make no compute resource requirements.
59
-
60
- See the [walkthrough](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
61
- for an example of how to avoid this problem.
62
- -->
63
- - 不同的团队可以在不同的命名空间下工作,这可以通过
64
- [ RBAC] ( /zh-cn/docs/reference/access-authn-authz/rbac/ ) 强制执行。
65
- - 集群管理员可以为每个命名空间创建一个或多个 ResourceQuota 对象。
84
+
85
+ You can apply a [scope](#quota-scopes) to a ResourceQuota to limit where it applies.
86
+
87
+ - If creating or updating a resource violates a quota constraint, the control plane rejects that request with HTTP
88
+ status code `403 Forbidden`. The error includes a message explaining the constraint that would have been violated.
89
+ -->
66
90
- 当用户在命名空间下创建资源(如 Pod、Service 等)时,Kubernetes 的配额系统会跟踪集群的资源使用情况,
67
91
以确保使用的资源用量不超过 ResourceQuota 中定义的硬性资源限额。
68
- - 如果资源创建或者更新请求违反了配额约束,那么该请求会报错(HTTP 403 FORBIDDEN),
69
- 并在消息中给出有可能违反的约束。
70
- - 如果命名空间下的计算资源(如 ` cpu ` 和 ` memory ` )的配额被启用,
71
- 则用户必须为这些资源设定请求值(request)和约束值(limit),否则配额系统将拒绝 Pod 的创建。
72
- 提示: 可使用 ` LimitRanger ` 准入控制器来为没有设置计算资源需求的 Pod 设置默认值。
73
-
74
- 若想避免这类问题,请参考
75
- [ 演练] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/ ) 示例。
92
+
93
+ 你可以对 ResourceQuota 应用一个[ 范围] ( #quota-scopes ) ,以限制其适用的地方。
94
+
95
+ - 如果创建或更新资源违反了配额约束,控制平面将使用 HTTP 状态码
96
+ ` 403 Forbidden ` 拒绝该请求。错误信息包括解释将要违反的约束的说明。
97
+
98
+ <!--
99
+ - If quotas are enabled in a namespace for {{< glossary_tooltip text="resource" term_id="infrastructure-resource" >}}
100
+ such as `cpu` and `memory`, users must specify requests or limits for those values when they define a Pod; otherwise,
101
+ the quota system may reject pod creation.
102
+
103
+ The resource quota [walkthrough](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
104
+ shows an example of how to avoid this problem.
105
+ -->
106
+ - 如果在命名空间中为诸如 ` cpu ` 和 ` memory `
107
+ 的{{< glossary_tooltip text="资源" term_id="infrastructure-resource" >}}启用了配额,
108
+ 用户在定义 Pod 时必须指定这些值的请求或限制;否则,配额系统可能会拒绝 Pod 创建。
109
+
110
+ 资源配额[ 演练] ( /zh-cn/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/ ) 展示了一个如何避免此问题的示例。
76
111
77
112
{{< note >}}
113
+ <!--
114
+ * You can define a [LimitRange](/docs/concepts/policy/limit-range/)
115
+ to force defaults on pods that make no compute resource requirements (so that users don't have to remember to do that).
116
+ ->
117
+ * 可以定义 [LimitRange](/docs/concepts/policy/limit-range/) 强制
118
+ Pod 在没有计算资源需求的情况下设置默认值(这样用户就不必记住要这样做)。
119
+ {{< /note >}}
120
+
121
+ <!--
122
+ You often do not create Pods directly; for example, you more usually create a [workload management](/docs/concepts/workloads/controllers/)
123
+ object such as a {{< glossary_tooltip term_id="deployment" >}}. If you create a Deployment that tries to use more
124
+ resources than are available, the creation of the Deployment (or other workload management object) **succeeds**, but
125
+ the Deployment may not be able to get all of the Pods it manages to exist. In that case you can check the status of
126
+ the Deployment, for example with `kubectl describe`, to see what has happened.
127
+ -->
128
+ 你通常不会直接创建 Pod;例如,你更常创建一个[ 工作负载管理] ( /zh-cn/docs/concepts/workloads/controllers/ ) 对象,
129
+ 如 {{< glossary_tooltip term_id="deployment" >}}。
130
+ 如果你创建了一个尝试使用超出可用资源的 Deployment(或其他工作负载管理对象),
131
+ 其创建** 会成功** ,但 Deployment 可能无法使其管理的所有 Pod 都运行起来。
132
+ 在这种情况下,你可以使用 ` kubectl describe ` 等命令检查 Deployment 的状态,
133
+ 以查看发生了什么。
134
+
78
135
<!--
79
136
- For `cpu` and `memory` resources, ResourceQuotas enforce that **every**
80
137
(new) pod in that namespace sets a limit for that resource.
@@ -93,12 +150,11 @@ a default request for these resources.
93
150
- 对于 ` cpu ` 和 ` memory ` 资源:ResourceQuota 强制该命名空间中的** 每个** (新)Pod 为该资源设置限制。
94
151
如果你在命名空间中为 ` cpu ` 和 ` memory ` 实施资源配额,
95
152
你或其他客户端** 必须** 为你提交的每个新 Pod 指定该资源的 ` requests ` 或 ` limits ` 。
96
- 否则,控制平面可能会拒绝接纳该 Pod。
153
+ 否则,控制平面可能会拒绝接纳该 Pod
97
154
- 对于其他资源:ResourceQuota 可以工作,并且会忽略命名空间中的 Pod,而无需为该资源设置限制或请求。
98
155
这意味着,如果资源配额限制了此命名空间的临时存储,则可以创建没有限制/请求临时存储的新 Pod。
99
- 你可以使用[ 限制范围] ( /zh-cn/docs/concepts/policy/limit-range/ ) 自动设置对这些资源的默认请求。
100
156
101
- {{< /note >}}
157
+ 你可以使用 [ LimitRange ] ( /zh-cn/docs/concepts/policy/limit-range/ ) 自动设置对这些资源的默认请求。
102
158
103
159
<!--
104
160
The name of a ResourceQuota object must be a valid
@@ -125,13 +181,9 @@ Examples of policies that could be created using namespaces and quotas are:
125
181
<!--
126
182
In the case where the total capacity of the cluster is less than the sum of the quotas of the namespaces,
127
183
there may be contention for resources. This is handled on a first-come-first-served basis.
128
-
129
- Neither contention nor changes to quota will affect already created resources.
130
184
-->
131
185
在集群容量小于各命名空间配额总和的情况下,可能存在资源竞争。资源竞争时,Kubernetes 系统会遵循先到先得的原则。
132
186
133
- 不管是资源竞争还是配额的修改,都不会影响已经创建的资源使用对象。
134
-
135
187
<!--
136
188
## Enabling Resource Quota
137
189
@@ -1357,13 +1409,16 @@ and it is to be created in a namespace other than `kube-system`.
1357
1409
# # {{% heading "whatsnext" %}}
1358
1410
1359
1411
<!--
1360
- - See [ResourceQuota design document](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_resource_quota.md)
1361
- for more information.
1362
1412
- See a [detailed example for how to use resource quota](/docs/tasks/administer-cluster/quota-api-object/).
1363
- - Read [Quota support for priority class design document](https://git.k8s.io/design-proposals-archive/scheduling/pod-priority-resourcequota.md).
1364
- - See [LimitedResources](https://github.com/kubernetes/kubernetes/pull/36765).
1413
+ - Read the ResourceQuota [API reference](/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
1414
+ - Learn about [LimitRanges](/docs/concepts/policy/limit-range/)
1415
+ - You can read the historical [ResourceQuota design document](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_resource_quota.md)
1416
+ for more information.
1417
+ - You can also read the [Quota support for priority class design document](https://git.k8s.io/design-proposals-archive/scheduling/pod-priority-resourcequota.md).
1365
1418
-->
1366
- - 参阅[资源配额设计文档](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_resource_quota.md)。
1367
1419
- 参阅[如何使用资源配额的详细示例](/zh-cn/docs/tasks/administer-cluster/quota-api-object/)。
1368
- - 参阅[优先级类配额支持的设计文档](https://git.k8s.io/design-proposals-archive/scheduling/pod-priority-resourcequota.md)了解更多信息。
1369
- - 参阅 [LimitedResources](https://github.com/kubernetes/kubernetes/pull/36765)。
1420
+ - 阅读 ResourceQuota [API 参考](/zh-cn/docs/reference/kubernetes-api/policy-resources/resource-quota-v1/)
1421
+ - 了解 [LimitRanges](/zh-cn/docs/concepts/policy/limit-range/)
1422
+ - 你可以阅读历史的
1423
+ [ResourceQuota 设计文档](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_resource_quota.md)获取更多信息。
1424
+ - 你也可以阅读[优先级类配额支持设计文档](https://git.k8s.io/design-proposals-archive/scheduling/pod-priority-resourcequota.md)。
0 commit comments