Skip to content

Commit f1db833

Browse files
author
Davi Garcia
committed
Replace embedded examples with links to related task docs
Signed-off-by: Davi Garcia <[email protected]>
1 parent 02afab2 commit f1db833

File tree

1 file changed

+6
-329
lines changed

1 file changed

+6
-329
lines changed

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

Lines changed: 6 additions & 329 deletions
Original file line numberDiff line numberDiff line change
@@ -56,337 +56,14 @@ there may be contention for resources. In this case, the Containers or Pods will
5656

5757
Neither contention nor changes to a LimitRange will affect already created resources.
5858

59-
## Limiting Container compute resources
60-
61-
The following section discusses the creation of a LimitRange acting at Container Level.
62-
A Pod with 04 Containers is first created. Each Container within the Pod has a specific `spec.resource` configuration.
63-
Each Container within the Pod is handled differently by the `LimitRanger` admission controller.
64-
65-
Create a namespace `limitrange-demo` using the following kubectl command:
66-
67-
```shell
68-
kubectl create namespace limitrange-demo
69-
```
70-
71-
To avoid passing the target limitrange-demo in your kubectl commands, change your context with the following command:
72-
73-
```shell
74-
kubectl config set-context --current --namespace=limitrange-demo
75-
```
76-
77-
Here is the configuration file for a LimitRange object:
78-
{{< codenew file="admin/resource/limit-mem-cpu-container.yaml" >}}
79-
80-
This object defines minimum and maximum CPU/Memory limits, default CPU/Memory requests, and default limits for CPU/Memory resources to be apply to containers.
81-
82-
Create the `limit-mem-cpu-per-container` LimitRange with the following kubectl command:
83-
84-
```shell
85-
kubectl create -f https://k8s.io/examples/admin/resource/limit-mem-cpu-container.yaml
86-
```
87-
88-
```shell
89-
kubectl describe limitrange/limit-mem-cpu-per-container
90-
```
91-
92-
```shell
93-
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
94-
---- -------- --- --- --------------- ------------- -----------------------
95-
Container cpu 100m 800m 110m 700m -
96-
Container memory 99Mi 1Gi 111Mi 900Mi -
97-
```
98-
99-
Here is the configuration file for a Pod with 04 Containers to demonstrate LimitRange features:
100-
{{< codenew file="admin/resource/limit-range-pod-1.yaml" >}}
101-
102-
Create the `busybox1` Pod:
103-
104-
```shell
105-
kubectl apply -f https://k8s.io/examples/admin/resource/limit-range-pod-1.yaml
106-
```
107-
108-
### Container spec with valid CPU/Memory requests and limits
109-
110-
View the `busybox-cnt01` resource configuration:
111-
112-
```shell
113-
kubectl get po/busybox1 -o json | jq ".spec.containers[0].resources"
114-
```
115-
116-
```json
117-
{
118-
"limits": {
119-
"cpu": "500m",
120-
"memory": "200Mi"
121-
},
122-
"requests": {
123-
"cpu": "100m",
124-
"memory": "100Mi"
125-
}
126-
}
127-
```
128-
129-
- The `busybox-cnt01` Container inside `busybox` Pod defined `requests.cpu=100m` and `requests.memory=100Mi`.
130-
- `100m <= 500m <= 800m` , The Container cpu limit (500m) falls inside the authorized CPU LimitRange.
131-
- `99Mi <= 200Mi <= 1Gi` , The Container memory limit (200Mi) falls inside the authorized Memory LimitRange.
132-
- No request/limits ratio validation for CPU/Memory, so the Container is valid and created.
133-
134-
135-
### Container spec with a valid CPU/Memory requests but no limits
136-
137-
View the `busybox-cnt02` resource configuration
138-
139-
```shell
140-
kubectl get po/busybox1 -o json | jq ".spec.containers[1].resources"
141-
```
142-
143-
```json
144-
{
145-
"limits": {
146-
"cpu": "700m",
147-
"memory": "900Mi"
148-
},
149-
"requests": {
150-
"cpu": "100m",
151-
"memory": "100Mi"
152-
}
153-
}
154-
```
155-
- The `busybox-cnt02` Container inside `busybox1` Pod defined `requests.cpu=100m` and `requests.memory=100Mi` but not limits for cpu and memory.
156-
- The Container does not have a limits section. The default limits defined in the `limit-mem-cpu-per-container` LimitRange object are injected in to this Container: `limits.cpu=700mi` and `limits.memory=900Mi`.
157-
- `100m <= 700m <= 800m` , The Container cpu limit (700m) falls inside the authorized CPU limit range.
158-
- `99Mi <= 900Mi <= 1Gi` , The Container memory limit (900Mi) falls inside the authorized Memory limit range.
159-
- No request/limits ratio set, so the Container is valid and created.
160-
161-
162-
### Container spec with a valid CPU/Memory limits but no requests
163-
164-
View the `busybox-cnt03` resource configuration:
165-
166-
```shell
167-
kubectl get po/busybox1 -o json | jq ".spec.containers[2].resources"
168-
```
169-
```json
170-
{
171-
"limits": {
172-
"cpu": "500m",
173-
"memory": "200Mi"
174-
},
175-
"requests": {
176-
"cpu": "500m",
177-
"memory": "200Mi"
178-
}
179-
}
180-
```
181-
182-
- The `busybox-cnt03` Container inside `busybox1` Pod defined `limits.cpu=500m` and `limits.memory=200Mi` but no `requests` for cpu and memory.
183-
- The Container does not define a request section. The default request defined in the limit-mem-cpu-per-container LimitRange is not used to fill its limits section, but the limits defined by the Container are set as requests `limits.cpu=500m` and `limits.memory=200Mi`.
184-
- `100m <= 500m <= 800m` , The Container cpu limit (500m) falls inside the authorized CPU limit range.
185-
- `99Mi <= 200Mi <= 1Gi` , The Container memory limit (200Mi) falls inside the authorized Memory limit range.
186-
- No request/limits ratio set, so the Container is valid and created.
187-
188-
### Container spec with no CPU/Memory requests/limits
189-
190-
View the `busybox-cnt04` resource configuration:
191-
192-
```shell
193-
kubectl get po/busybox1 -o json | jq ".spec.containers[3].resources"
194-
```
195-
196-
```json
197-
{
198-
"limits": {
199-
"cpu": "700m",
200-
"memory": "900Mi"
201-
},
202-
"requests": {
203-
"cpu": "110m",
204-
"memory": "111Mi"
205-
}
206-
}
207-
```
208-
209-
- The `busybox-cnt04` Container inside `busybox1` define neither `limits` nor `requests`.
210-
- The Container do not define a limit section, the default limit defined in the limit-mem-cpu-per-container LimitRange is used to fill its request
211-
`limits.cpu=700m and` `limits.memory=900Mi` .
212-
- The Container do not define a request section, the defaultRequest defined in the `limit-mem-cpu-per-container` LimitRange is used to fill its request section requests.cpu=110m and requests.memory=111Mi
213-
- `100m <= 700m <= 800m` , The Container cpu limit (700m) falls inside the authorized CPU limit range.
214-
- `99Mi <= 900Mi <= 1Gi` , The Container memory limit (900Mi) falls inside the authorized Memory limit range .
215-
- No request/limits ratio set, so the Container is valid and created.
216-
217-
All Containers defined in the `busybox` Pod passed LimitRange validations, so this the Pod is valid and created in the namespace.
218-
219-
## Limiting Pod compute resources
220-
221-
The following section discusses how to constrain resources at the Pod level.
222-
223-
{{< codenew file="admin/resource/limit-mem-cpu-pod.yaml" >}}
224-
225-
Without having to delete the `busybox1` Pod, create the `limit-mem-cpu-pod` LimitRange in the `limitrange-demo` namespace:
226-
227-
```shell
228-
kubectl apply -f https://k8s.io/examples/admin/resource/limit-mem-cpu-pod.yaml
229-
```
230-
The LimitRange is created and limits CPU to 2 Core and Memory to 2Gi per Pod:
231-
232-
```shell
233-
limitrange/limit-mem-cpu-per-pod created
234-
```
235-
236-
Describe the `limit-mem-cpu-per-pod` limit object using the following kubectl command:
237-
238-
```shell
239-
kubectl describe limitrange/limit-mem-cpu-per-pod
240-
```
241-
242-
```shell
243-
Name: limit-mem-cpu-per-pod
244-
Namespace: limitrange-demo
245-
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
246-
---- -------- --- --- --------------- ------------- -----------------------
247-
Pod cpu - 2 - - -
248-
Pod memory - 2Gi - - -
249-
```
250-
251-
Now create the `busybox2` Pod:
252-
253-
{{< codenew file="admin/resource/limit-range-pod-2.yaml" >}}
254-
255-
```shell
256-
kubectl apply -f https://k8s.io/examples/admin/resource/limit-range-pod-2.yaml
257-
```
258-
259-
The `busybox2` Pod definition is identical to `busybox1`, but an error is reported since the Pod's resources are now limited:
260-
261-
```shell
262-
Error from server (Forbidden): error when creating "limit-range-pod-2.yaml": pods "busybox2" is forbidden: [maximum cpu usage per Pod is 2, but limit is 2400m., maximum memory usage per Pod is 2Gi, but limit is 2306867200.]
263-
```
264-
265-
```shell
266-
kubectl get po/busybox1 -o json | jq ".spec.containers[].resources.limits.memory"
267-
"200Mi"
268-
"900Mi"
269-
"200Mi"
270-
"900Mi"
271-
```
272-
273-
`busybox2` Pod will not be admitted on the cluster since the total memory limit of its Container is greater than the limit defined in the LimitRange.
274-
`busybox1` will not be evicted since it was created and admitted on the cluster before the LimitRange creation.
275-
276-
## Limiting Storage resources
277-
278-
You can enforce minimum and maximum size of [storage resources](/docs/concepts/storage/persistent-volumes/) that can be requested by each PersistentVolumeClaim in a namespace using a LimitRange:
279-
280-
{{< codenew file="admin/resource/storagelimits.yaml" >}}
281-
282-
Apply the YAML using `kubectl create`:
283-
284-
```shell
285-
kubectl create -f https://k8s.io/examples/admin/resource/storagelimits.yaml
286-
```
287-
288-
```shell
289-
limitrange/storagelimits created
290-
```
291-
292-
Describe the created object:
293-
294-
```shell
295-
kubectl describe limits/storagelimits
296-
```
297-
298-
The output should look like:
299-
300-
```shell
301-
Name: storagelimits
302-
Namespace: limitrange-demo
303-
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
304-
---- -------- --- --- --------------- ------------- -----------------------
305-
PersistentVolumeClaim storage 1Gi 2Gi - - -
306-
```
307-
308-
{{< codenew file="admin/resource/pvc-limit-lower.yaml" >}}
309-
310-
```shell
311-
kubectl create -f https://k8s.io/examples/admin/resource/pvc-limit-lower.yaml
312-
```
313-
314-
While creating a PVC with `requests.storage` lower than the Min value in the LimitRange, an Error thrown by the server:
315-
316-
```shell
317-
Error from server (Forbidden): error when creating "pvc-limit-lower.yaml": persistentvolumeclaims "pvc-limit-lower" is forbidden: minimum storage usage per PersistentVolumeClaim is 1Gi, but request is 500Mi.
318-
```
319-
320-
Same behaviour is noted if the `requests.storage` is greater than the Max value in the LimitRange:
321-
322-
{{< codenew file="admin/resource/pvc-limit-greater.yaml" >}}
323-
324-
```shell
325-
kubectl create -f https://k8s.io/examples/admin/resource/pvc-limit-greater.yaml
326-
```
327-
328-
```shell
329-
Error from server (Forbidden): error when creating "pvc-limit-greater.yaml": persistentvolumeclaims "pvc-limit-greater" is forbidden: maximum storage usage per PersistentVolumeClaim is 2Gi, but request is 5Gi.
330-
```
331-
332-
## Limits/Requests Ratio
333-
334-
If `LimitRangeItem.maxLimitRequestRatio` is specified in the `LimitRangeSpec`, the named resource must have a request and limit that are both non-zero where limit divided by request is less than or equal to the enumerated value.
335-
336-
The following LimitRange enforces memory limit to be at most twice the amount of the memory request for any Pod in the namespace:
337-
338-
{{< codenew file="admin/resource/limit-memory-ratio-pod.yaml" >}}
339-
340-
```shell
341-
kubectl apply -f https://k8s.io/examples/admin/resource/limit-memory-ratio-pod.yaml
342-
```
343-
344-
Describe the <limit-memory-ratio-pod> LimitRange with the following kubectl command:
345-
346-
```shell
347-
kubectl describe limitrange/limit-memory-ratio-pod
348-
```
349-
350-
```shell
351-
Name: limit-memory-ratio-pod
352-
Namespace: limitrange-demo
353-
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
354-
---- -------- --- --- --------------- ------------- -----------------------
355-
Pod memory - - - - 2
356-
```
357-
358-
Create a pod with `requests.memory=100Mi` and `limits.memory=300Mi`:
359-
360-
{{< codenew file="admin/resource/limit-range-pod-3.yaml" >}}
361-
362-
```shell
363-
kubectl apply -f https://k8s.io/examples/admin/resource/limit-range-pod-3.yaml
364-
```
365-
366-
The pod creation failed as the ratio here (`3`) is greater than the enforced limit (`2`) in `limit-memory-ratio-pod` LimitRange:
367-
368-
```
369-
Error from server (Forbidden): error when creating "limit-range-pod-3.yaml": pods "busybox3" is forbidden: memory max limit to request ratio per Pod is 2, but provided ratio is 3.000000.
370-
```
371-
372-
## Clean up
373-
374-
Delete the `limitrange-demo` namespace to free all resources:
375-
376-
```shell
377-
kubectl delete ns limitrange-demo
378-
```
379-
Change your context to `default` namespace with the following command:
380-
381-
```shell
382-
kubectl config set-context --current --namespace=default
383-
```
384-
38559
## Examples
38660

387-
- See [a tutorial on how to limit compute resources per namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/) .
388-
- Check [how to limit storage consumption](/docs/tasks/administer-cluster/limit-storage-consumption/#limitrange-to-limit-requests-for-storage).
389-
- See a [detailed example on quota per namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/).
61+
- See [how to configure minimum and maximum CPU constraints per namespace](/docs/tasks/administer-cluster/manage-resources/cpu-constraint-namespace/).
62+
- See [how to configure minimum and maximum Memory constraints per namespace](https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/memory-constraint-namespace/).
63+
- See [how to configure default CPU Requests and Limits per namespace](https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/cpu-default-namespace/).
64+
- See [how to configure default Memory Requests and Limits per namespace](https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/).
65+
- Check [how to configure minimum and maximum Storage consumption per namespace](/docs/tasks/administer-cluster/limit-storage-consumption/#limitrange-to-limit-requests-for-storage).
66+
- See a [detailed example on configuring quota per namespace](/docs/tasks/administer-cluster/quota-memory-cpu-namespace/).
39067

39168
{{% /capture %}}
39269

0 commit comments

Comments
 (0)