Skip to content

Commit 0eabe49

Browse files
limit ranger clarification
1 parent b3baa90 commit 0eabe49

File tree

5 files changed

+89
-14
lines changed

5 files changed

+89
-14
lines changed

content/en/docs/concepts/policy/limit-range.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,68 @@ weight: 10
99
<!-- overview -->
1010

1111
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
15+
{{< glossary_tooltip text="namespace" term_id="namespace" >}}.
16+
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.
1419

1520
<!-- body -->
1621

1722
A _LimitRange_ provides constraints that can:
1823

1924
- 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.
2126
- Enforce a ratio between request and limit for a resource in a namespace.
2227
- Set default request/limit for compute resources in a namespace and automatically inject them to Containers at runtime.
2328

24-
## Enabling LimitRange
25-
26-
LimitRange support has been enabled by default since Kubernetes 1.10.
2729

2830
A LimitRange is enforced in a particular namespace when there is a
2931
LimitRange object in that namespace.
3032

3133
The name of a LimitRange object must be a valid
3234
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
3335

34-
### Overview of Limit Range
36+
## Constraints on resource limits and requests
3537

36-
- 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
4145
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:
56+
57+
{{< codenew file="concepts/policy/limit-range/problematic-limit-range.yaml" >}}
58+
59+
60+
The following Pod that declares the Request of `700m`, but not the limit:
61+
62+
{{< codenew file="concepts/policy/limit-range/example-conflict-with-limitrange-cpu.yaml" >}}
63+
64+
65+
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:
68+
69+
{{< codenew file="concepts/policy/limit-range/example-no-conflict-with-limitrange-cpu.yaml" >}}
70+
71+
## Example resource constraints
4372

44-
Examples of policies that could be created using limit range are:
73+
Examples of policies that could be created using `LimitRange` are:
4574

4675
- 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.
4776
- 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.

content/en/docs/tasks/administer-cluster/manage-resources/memory-default-namespace.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ resources:
167167
memory: 128Mi
168168
```
169169

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+
170178
## Motivation for default memory limits and requests
171179

172180
If your namespace has a memory {{< glossary_tooltip text="resource quota" term_id="resource-quota" >}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: example-conflict-with-limitrange-cpu
5+
spec:
6+
containers:
7+
- name: demo
8+
image: registry.k8s.io/pause:2.0
9+
resources:
10+
requests:
11+
cpu: 700m
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: example-no-conflict-with-limitrange-cpu
5+
spec:
6+
containers:
7+
- name: demo
8+
image: registry.k8s.io/pause:2.0
9+
resources:
10+
requests:
11+
cpu: 700m
12+
limits:
13+
cpu: 700m
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: LimitRange
3+
metadata:
4+
name: cpu-resource-constraint
5+
spec:
6+
limits:
7+
- default: # this section defines default limits
8+
cpu: 500m
9+
defaultRequest: # this section defines default requests
10+
cpu: 500m
11+
max: # max and min define the limit range
12+
cpu: "1"
13+
min:
14+
cpu: 100m

0 commit comments

Comments
 (0)