Chapter 16. Resource Limits
16.1. Overview
A LimitRange
object enumerates compute resource constraints in a project at the pod and container level. This allows you to specify the amount of resources that a pod or container can consume.
16.2. Setting Limit Range Constraints
All resource create and modification requests are evaluated against each LimitRange
object in the project. If the resource violates any of the enumerated constraints, then the resource is rejected. If the resource does not set an explicit value, and if the constraint supports a default value, then the default value is applied to the resource.
Example 16.1. Limit Range Object Definition
apiVersion: "v1" kind: "LimitRange" metadata: name: "limits" 1 spec: limits: - type: "Pod" max: cpu: "2" 2 memory: "1Gi" 3 min: cpu: "200m" 4 memory: "6Mi" 5 - type: "Container" max: cpu: "2" 6 memory: "1Gi" 7 min: cpu: "100m" 8 memory: "4Mi" 9 default: cpu: "300m" 10 memory: "200Mi" 11 defaultRequest: cpu: "200m" 12 memory: "100Mi" 13 maxLimitRequestRatio: cpu: "10" 14
- 1
- The name of the limit range document.
- 2
- The maximum amount of CPU that a pod can request on a node across all containers.
- 3
- The maximum amount of memory that a pod can request on a node across all containers.
- 4
- The minimum amount of CPU that a pod can request on a node across all containers.
- 5
- The minimum amount of memory that a pod can request on a node across all containers.
- 6
- The maximum amount of CPU that a single container in a pod can request.
- 7
- The maximum amount of memory that a single container in a pod can request.
- 8
- The minimum amount of CPU that a single container in a pod can request.
- 9
- The minimum amount of memory that a single container in a pod can request.
- 10
- The default amount of CPU that a container will be limited to use if not specified.
- 11
- The default amount of memory that a container will be limited to use if not specified.
- 12
- The default amount of CPU that a container will request to use if not specified.
- 13
- The default amount of memory that a container will request to use if not specified.
- 14
- The maximum amount of CPU burst that a container can make as a ratio of its limit over request.
16.2.1. Container Limits
Supported Resources:
- CPU
- Memory
Supported Constraints:
Per container, the following must hold true if specified:
Constraint | Behavior |
---|---|
| Min[resource] ⇐ container.resources.requests[resource] (required) ⇐ container/resources.limits[resource] (optional)
If the configuration defines a |
| container.resources.limits[resource] (required) ⇐ Max[resource]
If the configuration defines a |
| MaxLimitRequestRatio[resource] ⇐ ( container.resources.limits[resource] / container.resources.requests[resource])
If a configuration defines a |
Supported Defaults:
- Default[resource] - defaults container.resources.limit[resource] to specified value if none
- Default Requests[resource] - defaults container.resources.requests[resource] to specified value if none
16.2.2. Pod Limits
Supported Resources:
- CPU
- Memory
Supported Constraints:
Across all containers in a pod, the following must hold true:
Constraint | Enforced Behavior |
---|---|
| Min[resource] less than or equal to container.resources.requests[resource] (required) less than or equal to container.resources.limits[resource] (optional) |
| container.resources.limits[resource] (required) less than or equal to Max[resource] |
| MaxLimitRequestRatio[resource] less than or equal to ( container.resources.limits[resource] / container.resources.requests[resource]) |
16.3. Creating a Limit Range
To apply a limit range to a project, create a limit range object definition on your file system to your desired specifications, then run:
$ oc create -f <limit_range_file>
16.4. Viewing Limits
To view limits enforced in a project:
$ oc get limits NAME limits $ oc describe limits limits Name: limits Namespace: default Type Resource Min Max Request Limit Limit/Request ---- -------- --- --- ------- ----- ------------- Pod memory 6Mi 1Gi - - - Pod cpu 200m 2 - - - Container cpu 100m 2 200m 300m 10 Container memory 4Mi 1Gi 100Mi 200Mi -
16.5. Deleting Limits
Remove any active limit range to no longer enforce the limits of a project:
$ oc delete limits <limit_name>