Skip to content

Commit 9a0df09

Browse files
authored
Merge pull request #48941 from my-git9/pp-14758
[zh-cn]sync limit-range.md
2 parents 3ba842d + b7c80da commit 9a0df09

File tree

1 file changed

+80
-42
lines changed

1 file changed

+80
-42
lines changed

content/zh-cn/docs/concepts/policy/limit-range.md

Lines changed: 80 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 限制范围
2+
title: 限制范围(LimitRange)
33
api_metadata:
44
- apiVersion: "v1"
55
kind: "LimitRange"
@@ -20,18 +20,24 @@ weight: 10
2020
<!-- overview -->
2121

2222
<!--
23-
By default, containers run with unbounded [compute resources](/docs/concepts/configuration/manage-resources-containers/) on a Kubernetes cluster.
23+
By default, containers run with unbounded
24+
[compute resources](/docs/concepts/configuration/manage-resources-containers/) on a Kubernetes cluster.
2425
Using Kubernetes [resource quotas](/docs/concepts/policy/resource-quotas/),
2526
administrators (also termed _cluster operators_) can restrict consumption and creation
2627
of cluster resources (such as CPU time, memory, and persistent storage) within a specified
2728
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
28-
Within a namespace, a {{< glossary_tooltip text="Pod" term_id="Pod" >}} can consume as much CPU and memory as is allowed by the ResourceQuotas that apply to that namespace. As a cluster operator, or as a namespace-level administrator, you might also be concerned about making sure that a single object cannot monopolize all available resources within a namespace.
29-
30-
A LimitRange is a policy to constrain the resource allocations (limits and requests) that you can specify for each applicable object kind (such as Pod or {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}}) in a namespace.
29+
Within a namespace, a {{< glossary_tooltip text="Pod" term_id="Pod" >}} can consume as much CPU and memory
30+
as is allowed by the ResourceQuotas that apply to that namespace.
31+
As a cluster operator, or as a namespace-level administrator, you might also be concerned
32+
about making sure that a single object cannot monopolize all available resources within a namespace.
33+
34+
A LimitRange is a policy to constrain the resource allocations (limits and requests) that you can specify for
35+
each applicable object kind (such as Pod or {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}})
36+
in a namespace.
3137
-->
3238
默认情况下, Kubernetes 集群上的容器运行使用的[计算资源](/zh-cn/docs/concepts/configuration/manage-resources-containers/)没有限制。
3339
使用 Kubernetes [资源配额](/zh-cn/docs/concepts/policy/resource-quotas/)
34-
管理员(也称为 **集群操作者**)可以在一个指定的{{< glossary_tooltip text="命名空间" term_id="namespace" >}}内限制集群资源的使用与创建。
40+
管理员(也称为**集群操作者**)可以在一个指定的{{< glossary_tooltip text="命名空间" term_id="namespace" >}}内限制集群资源的使用与创建。
3541
在命名空间中,一个 {{< glossary_tooltip text="Pod" term_id="Pod" >}} 最多能够使用命名空间的资源配额所定义的 CPU 和内存用量。
3642
作为集群操作者或命名空间级的管理员,你可能也会担心如何确保一个 Pod 不会垄断命名空间内所有可用的资源。
3743

@@ -45,11 +51,12 @@ LimitRange 是限制命名空间内可为每个适用的对象类别
4551
A _LimitRange_ provides constraints that can:
4652
4753
- Enforce minimum and maximum compute resources usage per Pod or Container in a namespace.
48-
- Enforce minimum and maximum storage request per {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} in a namespace.
54+
- Enforce minimum and maximum storage request per
55+
{{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} in a namespace.
4956
- Enforce a ratio between request and limit for a resource in a namespace.
50-
- Set default request/limit for compute resources in a namespace and automatically inject them to Containers at runtime.
57+
- Set default request/limit for compute resources in a namespace and automatically
58+
inject them to Containers at runtime.
5159
-->
52-
5360
一个 **LimitRange(限制范围)** 对象提供的限制能够做到:
5461

5562
- 在一个命名空间中实施对每个 Pod 或 Container 最小和最大的资源使用量的限制。
@@ -59,10 +66,11 @@ A _LimitRange_ provides constraints that can:
5966
- 设置一个命名空间中对计算资源的默认申请/限制值,并且自动的在运行时注入到多个 Container 中。
6067

6168
<!--
62-
A LimitRange is enforced in a particular namespace when there is a
63-
LimitRange object in that namespace.
69+
Kubernetes constrains resource allocations to Pods in a particular namespace
70+
whenever there is at least one LimitRange object in that namespace.
6471
-->
65-
当某命名空间中有一个 LimitRange 对象时,将在该命名空间中实施 LimitRange 限制。
72+
只要特定命名空间中至少有一个 LimitRange 对象,Kubernetes 就会限制对该命名空间中的
73+
Pod 的资源分配。
6674

6775
<!--
6876
The name of a LimitRange object must be a valid
@@ -75,46 +83,69 @@ LimitRange 的名称必须是合法的
7583
## Constraints on resource limits and requests
7684
7785
- The administrator creates a LimitRange in a namespace.
78-
- Users create (or try to create) objects in that namespace, such as Pods or PersistentVolumeClaims.
79-
- First, the `LimitRange` admission controller applies default request and limit values for all Pods (and their containers) that do not set compute resource requirements.
80-
- Second, the `LimitRange` tracks usage to ensure it does not exceed resource minimum, maximum and ratio defined in any `LimitRange` present in the namespace.
81-
- If you attempt to create or update an object (Pod or PersistentVolumeClaim) that violates a `LimitRange` constraint, your request to the API server will fail with an HTTP status code `403 Forbidden` and a message explaining the constraint that has been violated.
82-
- If you add a `LimitRange` in a namespace that applies to compute-related resources such as
83-
`cpu` and `memory`, you must specify
84-
requests or limits for those values. Otherwise, the system may reject Pod creation.
85-
- `LimitRange` validations occur only at Pod admission stage, not on running Pods.
86+
- Users create (or try to create) objects in that namespace, such as Pods or
87+
PersistentVolumeClaims.
88+
- First, the LimitRange admission controller applies default request and limit values
89+
for all Pods (and their containers) that do not set compute resource requirements.
90+
- Second, the LimitRange tracks usage to ensure it does not exceed resource minimum,
91+
maximum and ratio defined in any LimitRange present in the namespace.
92+
- If you attempt to create or update an object (Pod or PersistentVolumeClaim) that violates
93+
a LimitRange constraint, your request to the API server will fail with an HTTP status
94+
code `403 Forbidden` and a message explaining the constraint that has been violated.
95+
- If you add a LimitRange in a namespace that applies to compute-related resources
96+
such as `cpu` and `memory`, you must specify requests or limits for those values.
97+
Otherwise, the system may reject Pod creation.
98+
- LimitRange validations occur only at Pod admission stage, not on running Pods.
8699
If you add or modify a LimitRange, the Pods that already exist in that namespace
87100
continue unchanged.
88-
- If two or more `LimitRange` objects exist in the namespace, it is not deterministic which default value will be applied.
101+
- If two or more LimitRange objects exist in the namespace, it is not deterministic
102+
which default value will be applied.
89103
-->
90104
## 资源限制和请求的约束 {#constraints-on-resource-limits-and-requests}
91105

92-
- 管理员在一个命名空间内创建一个 `LimitRange` 对象。
106+
- 管理员在一个命名空间内创建一个 LimitRange 对象。
93107
- 用户在此命名空间内创建(或尝试创建) Pod 和 PersistentVolumeClaim 等对象。
94-
- 首先,`LimitRange` 准入控制器对所有没有设置计算资源需求的所有 Pod(及其容器)设置默认请求值与限制值。
95-
- 其次,`LimitRange` 跟踪其使用量以保证没有超出命名空间中存在的任意 `LimitRange` 所定义的最小、最大资源使用量以及使用量比值。
96-
- 若尝试创建或更新的对象(Pod 和 PersistentVolumeClaim)违反了 `LimitRange` 的约束,
108+
- 首先,LimitRange 准入控制器对所有没有设置计算资源需求的所有 Pod(及其容器)设置默认请求值与限制值。
109+
- 其次,LimitRange 跟踪其使用量以保证没有超出命名空间中存在的任意 LimitRange 所定义的最小、最大资源使用量以及使用量比值。
110+
- 若尝试创建或更新的对象(Pod 和 PersistentVolumeClaim)违反了 LimitRange 的约束,
97111
向 API 服务器的请求会失败,并返回 HTTP 状态码 `403 Forbidden` 以及描述哪一项约束被违反的消息。
98-
- 若你在命名空间中添加 `LimitRange` 启用了对 `cpu``memory` 等计算相关资源的限制,
112+
- 若你在命名空间中添加 LimitRange 启用了对 `cpu``memory` 等计算相关资源的限制,
99113
你必须指定这些值的请求使用量与限制使用量。否则,系统将会拒绝创建 Pod。
100-
- `LimitRange` 的验证仅在 Pod 准入阶段进行,不对正在运行的 Pod 进行验证。
114+
- LimitRange 的验证仅在 Pod 准入阶段进行,不对正在运行的 Pod 进行验证。
101115
如果你添加或修改 LimitRange,命名空间中已存在的 Pod 将继续不变。
102-
- 如果命名空间中存在两个或更多 `LimitRange` 对象,应用哪个默认值是不确定的。
116+
- 如果命名空间中存在两个或更多 LimitRange 对象,应用哪个默认值是不确定的。
103117

104118
<!--
105119
## LimitRange and admission checks for Pods
106120
107-
A `LimitRange` does **not** check the consistency of the default values it applies. This means that a default value for the _limit_ that is set by `LimitRange` may be less than the _request_ value specified for the container in the spec that a client submits to the API server. If that happens, the final Pod will not be schedulable.
121+
A LimitRange does **not** check the consistency of the default values it applies.
122+
This means that a default value for the _limit_ that is set by LimitRange may be
123+
less than the _request_ value specified for the container in the spec that a client
124+
submits to the API server. If that happens, the final Pod will not be schedulable.
108125
109-
For example, you define a `LimitRange` with this manifest:
126+
For example, you define a LimitRange with this manifest:
110127
-->
111128
## Pod 的 LimitRange 和准入检查 {#limitrange-and-admission-checks-for-pod}
112129

113-
`LimitRange` **** 检查所应用的默认值的一致性。
114-
这意味着 `LimitRange` 设置的 **limit** 的默认值可能小于客户端提交给 API 服务器的规约中为容器指定的 **request** 值。
130+
LimitRange ****检查所应用的默认值的一致性。
131+
这意味着 LimitRange 设置的 **limit** 的默认值可能小于客户端提交给 API 服务器的规约中为容器指定的 **request** 值。
115132
如果发生这种情况,最终 Pod 将无法调度。
116133

117-
例如,你使用如下清单定义一个 `LimitRange`
134+
例如,你使用如下清单定义一个 LimitRange:
135+
136+
{{< note >}}
137+
<!--
138+
The following examples operate within the default namespace of your cluster, as the namespace
139+
parameter is undefined and the LimitRange scope is limited to the namespace level.
140+
This implies that any references or operations within these examples will interact
141+
with elements within the default namespace of your cluster. You can override the
142+
operating namespace by configuring namespace in the `metadata.namespace` field.
143+
-->
144+
以下示例在集群的 default 命名空间内运行,因为命名空间参数未定义,并且
145+
LimitRange 范围仅限于命名空间级别。
146+
这意味着这些示例中的任何引用或操作都将与集群的 default 命名空间中的元素进行交互。
147+
你可以通过在 `metadata.namespace` 字段中配置命名空间来覆盖要使用的命名空间。
148+
{{< /note >}}
118149

119150
{{% code_sample file="concepts/policy/limit-range/problematic-limit-range.yaml" %}}
120151

@@ -135,19 +166,23 @@ Pod "example-conflict-with-limitrange-cpu" is invalid: spec.containers[0].resour
135166
```
136167

137168
<!--
138-
If you set both `request` and `limit`, then that new Pod will be scheduled successfully even with the same `LimitRange` in place:
169+
If you set both `request` and `limit`, then that new Pod will be scheduled successfully
170+
even with the same LimitRange in place:
139171
-->
140-
如果你同时设置了 `request``limit`,那么即使使用相同的 `LimitRange`,新 Pod 也会被成功调度:
172+
如果你同时设置了 `request``limit`,那么即使使用相同的 LimitRange,新 Pod 也会被成功调度:
141173

142174
{{% code_sample file="concepts/policy/limit-range/example-no-conflict-with-limitrange-cpu.yaml" %}}
143175

144176
<!--
145177
## Example resource constraints
146178
147-
Examples of policies that could be created using `LimitRange` are:
179+
Examples of policies that could be created using LimitRange are:
148180
149-
- In a 2 node cluster with a capacity of 8 GiB RAM and 16 cores, constrain Pods in a namespace to request 100m of CPU with a max limit of 500m for CPU and request 200Mi for Memory with a max limit of 600Mi for Memory.
150-
- Define default CPU limit and request to 150m and memory default request to 300Mi for Containers started with no cpu and memory requests in their specs.
181+
- In a 2 node cluster with a capacity of 8 GiB RAM and 16 cores, constrain Pods in a
182+
namespace to request 100m of CPU with a max limit of 500m for CPU and request 200Mi
183+
for Memory with a max limit of 600Mi for Memory.
184+
- Define default CPU limit and request to 150m and memory default request to 300Mi for
185+
Containers started with no cpu and memory requests in their specs.
151186
-->
152187
## 资源约束示例 {#example-resource-constraints}
153188

@@ -159,8 +194,9 @@ Examples of policies that could be created using `LimitRange` are:
159194
150m,内存默认需求值 300Mi。
160195

161196
<!--
162-
In the case where the total limits of the namespace is less than the sum of the limits of the Pods/Containers,
163-
there may be contention for resources. In this case, the Containers or Pods will not be created.
197+
In the case where the total limits of the namespace is less than the sum of the limits
198+
of the Pods/Containers, there may be contention for resources. In this case, the
199+
Containers or Pods will not be created.
164200
-->
165201
在命名空间的总限制值小于 Pod 或 Container 的限制值的总和的情况下,可能会产生资源竞争。
166202
在这种情况下,将不会创建 Container 或 Pod。
@@ -182,7 +218,8 @@ For examples on using limits, see:
182218
- [how to configure minimum and maximum Storage consumption per namespace](/docs/tasks/administer-cluster/limit-storage-consumption/#limitrange-to-limit-requests-for-storage).
183219
- a [detailed example on configuring quota per namespace](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/).
184220
185-
Refer to the [LimitRanger design document](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_limit_range.md) for context and historical information.
221+
Refer to the [LimitRanger design document](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_limit_range.md)
222+
for context and historical information.
186223
-->
187224
关于使用限值的例子,可参阅:
188225

@@ -193,4 +230,5 @@ Refer to the [LimitRanger design document](https://git.k8s.io/design-proposals-a
193230
- [如何配置每个命名空间最小和最大存储使用量](/zh-cn/docs/tasks/administer-cluster/limit-storage-consumption/#limitrange-to-limit-requests-for-storage)
194231
- [配置每个命名空间的配额的详细例子](/zh-cn/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/)
195232

196-
有关上下文和历史信息,请参阅 [LimitRanger 设计文档](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_limit_range.md)
233+
有关上下文和历史信息,请参阅
234+
[LimitRanger 设计文档](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_limit_range.md)

0 commit comments

Comments
 (0)