You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/concepts/policy/limit-range.md
+43-14Lines changed: 43 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,39 +9,68 @@ weight: 10
9
9
<!-- overview -->
10
10
11
11
By default, containers run with unbounded [compute resources](/docs/concepts/configuration/manage-resources-containers/) on a Kubernetes cluster.
12
-
With resource quotas, cluster administrators can restrict resource consumption and creation on a {{< glossary_tooltip text="namespace" term_id="namespace" >}} basis.
13
-
Within a namespace, a Pod or Container can consume as much CPU and memory as defined by the namespace's resource quota. There is a concern that one Pod or Container could monopolize all available resources. A LimitRange is a policy to constrain resource allocations (to Pods or Containers) in a namespace.
12
+
Using Kubernetes [resource quotas](/docs/concepts/policy/resource-quotas/),
13
+
administrators (also termed _cluster operators_) can restrict consumption and creation
14
+
of cluster resources (such as CPU time, memory, and persistent storage) within a specified
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.
17
+
18
+
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.
14
19
15
20
<!-- body -->
16
21
17
22
A _LimitRange_ provides constraints that can:
18
23
19
24
- Enforce minimum and maximum compute resources usage per Pod or Container in a namespace.
20
-
- Enforce minimum and maximum storage request per PersistentVolumeClaim in a namespace.
25
+
- Enforce minimum and maximum storage request per {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} in a namespace.
21
26
- Enforce a ratio between request and limit for a resource in a namespace.
22
27
- Set default request/limit for compute resources in a namespace and automatically inject them to Containers at runtime.
23
28
24
-
## Enabling LimitRange
25
-
26
-
LimitRange support has been enabled by default since Kubernetes 1.10.
27
29
28
30
A LimitRange is enforced in a particular namespace when there is a
- The administrator creates one LimitRange in one namespace.
37
-
- Users create resources like Pods, Containers, and PersistentVolumeClaims in the namespace.
38
-
- The `LimitRanger` admission controller enforces defaults and limits for all Pods and Containers that do not set compute resource requirements and tracks usage to ensure it does not exceed resource minimum, maximum and ratio defined in any LimitRange present in the namespace.
39
-
- If creating or updating a resource (Pod, Container, PersistentVolumeClaim) that violates a LimitRange constraint, the request to the API server will fail with an HTTP status code `403 FORBIDDEN` and a message explaining the constraint that have been violated.
40
-
- If a LimitRange is activated in a namespace for compute resources like `cpu` and `memory`, users must specify
38
+
- The administrator creates a LimitRange in a namespace.
39
+
- Users create (or try to create) objects in that namespace, such as Pods or PersistentVolumeClaims.
40
+
- First, the `LimitRange` admission controller applies default request and limit values for all Pods (and their containers) that do not set compute resource requirements.
41
+
- Second, the `LimitRange` tracks usage to ensure it does not exceed resource minimum, maximum and ratio defined in any `LimitRange` present in the namespace.
42
+
- 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.
43
+
- If you add a `LimitRange` in a namespace that applies to compute-related resources such as
44
+
`cpu` and `memory`, you must specify
41
45
requests or limits for those values. Otherwise, the system may reject Pod creation.
42
-
- LimitRange validations occurs only at Pod Admission stage, not on Running Pods.
46
+
-`LimitRange` validations occur only at Pod admission stage, not on running Pods.
47
+
If you add or modify a LimitRange, the Pods that already exist in that namespace
48
+
continue unchanged.
49
+
- If two or more `LimitRange` objects exist in the namespace, it is not deterministic which default value will be applied.
50
+
51
+
## LimitRange and admission checks for Pods
52
+
53
+
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 scheduleable.
54
+
55
+
For example, if "LimitRange` is defined as following:
This Pod will not be scheduled with the error `Pod "ConflictingCpuSettings" is invalid: spec.containers[0].resources.requests: Invalid value: "700m": must be less than or equal to cpu limit`
66
+
67
+
If both, request and limit are set, the Pod will be scheduled successfully with the same `LimitRange` object:
Examples of policies that could be created using limit range are:
73
+
Examples of policies that could be created using `LimitRange` are:
45
74
46
75
- 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.
47
76
- 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.
Copy file name to clipboardExpand all lines: content/en/docs/tasks/administer-cluster/manage-resources/memory-default-namespace.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,6 +167,14 @@ resources:
167
167
memory: 128Mi
168
168
```
169
169
170
+
{{< note >}}
171
+
172
+
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 scheduleable.
173
+
See [Constraints on resource limits and requests](/docs/concepts/policy/limit-range/#constraints-on-resource-limits-and-requests) for more details.
174
+
175
+
{{< /note >}}
176
+
177
+
170
178
## Motivation for default memory limits and requests
171
179
172
180
If your namespace has a memory {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
0 commit comments