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
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:
### 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.
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:
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:
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:
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:
- 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/).
0 commit comments