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
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.
20
+
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.
21
+
As a cluster operator, or as a namespace-level administrator, you might also be concerned
22
+
about making sure that a single object cannot monopolize all available resources within a namespace.
20
23
21
-
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.
24
+
A LimitRange is a policy to constrain the resource allocations (limits and requests) that you can specify for
25
+
each applicable object kind (such as Pod or {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}}) in a namespace.
22
26
23
27
<!-- body -->
24
28
25
29
A _LimitRange_ provides constraints that can:
26
30
27
31
- Enforce minimum and maximum compute resources usage per Pod or Container in a namespace.
28
-
- Enforce minimum and maximum storage request per {{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} in a namespace.
32
+
- Enforce minimum and maximum storage request per
33
+
{{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} in a namespace.
29
34
- Enforce a ratio between request and limit for a resource in a namespace.
30
-
- Set default request/limit for compute resources in a namespace and automatically inject them to Containers at runtime.
35
+
- Set default request/limit for compute resources in a namespace and automatically
36
+
inject them to Containers at runtime.
31
37
32
-
33
-
A LimitRange is enforced in a particular namespace when there is a
34
-
LimitRange object in that namespace.
38
+
Kubernetes constrains resource allocations to Pods in a particular namespace
39
+
whenever there is at least one LimitRange object in that namespace.
- The administrator creates a LimitRange in a namespace.
42
-
- Users create (or try to create) objects in that namespace, such as Pods or PersistentVolumeClaims.
43
-
- First, the `LimitRange` admission controller applies default request and limit values for all Pods (and their containers) that do not set compute resource requirements.
44
-
- Second, the `LimitRange` tracks usage to ensure it does not exceed resource minimum, maximum and ratio defined in any `LimitRange` present in the namespace.
45
-
- 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.
46
-
- If you add a `LimitRange` in a namespace that applies to compute-related resources such as
47
-
`cpu` and `memory`, you must specify
48
-
requests or limits for those values. Otherwise, the system may reject Pod creation.
49
-
-`LimitRange` validations occur only at Pod admission stage, not on running Pods.
47
+
- Users create (or try to create) objects in that namespace, such as Pods or
48
+
PersistentVolumeClaims.
49
+
- First, the LimitRange admission controller applies default request and limit values
50
+
for all Pods (and their containers) that do not set compute resource requirements.
51
+
- Second, the LimitRange tracks usage to ensure it does not exceed resource minimum,
52
+
maximum and ratio defined in any LimitRange present in the namespace.
53
+
- If you attempt to create or update an object (Pod or PersistentVolumeClaim) that violates
54
+
a LimitRange constraint, your request to the API server will fail with anHTTP status
55
+
code `403 Forbidden` and a message explaining the constraint that has been violated.
56
+
- If you add a LimitRange in a namespace that applies to compute-related resources
57
+
such as `cpu` and `memory`, you must specify requests or limits for those values.
58
+
Otherwise, the system may reject Pod creation.
59
+
- LimitRange validations occur only at Pod admission stage, not on running Pods.
50
60
If you add or modify a LimitRange, the Pods that already exist in that namespace
51
61
continue unchanged.
52
-
- If two or more `LimitRange` objects exist in the namespace, it is not deterministic which default value will be applied.
62
+
- If two or more LimitRange objects exist in the namespace, it is not deterministic
63
+
which default value will be applied.
53
64
54
65
## LimitRange and admission checks for Pods
55
66
56
-
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.
67
+
A LimitRange does **not** check the consistency of the default values it applies.
68
+
This means that a default value for the _limit_ that is set by LimitRange may be
69
+
less than the _request_ value specified for the container in the spec that a client
70
+
submits to the API server. If that happens, the final Pod will not be schedulable.
57
71
58
-
For example, you define a `LimitRange` with this manifest:
72
+
For example, you define a LimitRange with below manifest:
73
+
{{< note >}}
74
+
The following examples operate within the default namespace of your cluster, as the namespace
75
+
parameter is undefined and the LimitRange scope is limited to the namespace level.
76
+
This implies that any references or operations within these examples will interact
77
+
with elements within the default namespace of your cluster. You can override the
78
+
operating namespace by configuring namespace in the `metadata.namespace` field.
then that Pod will not be scheduled, failing with an error similar to:
69
88
```
70
89
Pod "example-conflict-with-limitrange-cpu" is invalid: spec.containers[0].resources.requests: Invalid value: "700m": must be less than or equal to cpu limit
71
90
```
72
91
73
-
If you set both `request` and `limit`, then that new Pod will be scheduled successfully even with the same `LimitRange` in place:
92
+
If you set both `request` and `limit`, then that new Pod will be scheduled successfully
Examples of policies that could be created using `LimitRange` are:
99
+
Examples of policies that could be created using LimitRange are:
80
100
81
-
- 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.
82
-
- 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.
101
+
- In a 2 node cluster with a capacity of 8 GiB RAM and 16 cores, constrain Pods in a
102
+
namespace to request 100m of CPU with a max limit of 500m for CPU and request 200Mi
103
+
for Memory with a max limit of 600Mi for Memory.
104
+
- Define default CPU limit and request to 150m and memory default request to 300Mi for
105
+
Containers started with no cpu and memory requests in their specs.
83
106
84
-
In the case where the total limits of the namespace is less than the sum of the limits of the Pods/Containers,
85
-
there may be contention for resources. In this case, the Containers or Pods will not be created.
107
+
In the case where the total limits of the namespace is less than the sum of the limits
108
+
of the Pods/Containers, there may be contention for resources. In this case, the
109
+
Containers or Pods will not be created.
86
110
87
111
Neither contention nor changes to a LimitRange will affect already created resources.
88
112
@@ -97,5 +121,5 @@ For examples on using limits, see:
97
121
-[how to configure minimum and maximum Storage consumption per namespace](/docs/tasks/administer-cluster/limit-storage-consumption/#limitrange-to-limit-requests-for-storage).
98
122
- a [detailed example on configuring quota per namespace](/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/).
99
123
100
-
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.
101
-
124
+
Refer to the [LimitRanger design document](https://git.k8s.io/design-proposals-archive/resource-management/admission_control_limit_range.md)
0 commit comments