A limit range, defined by a LimitRange
object, enumerates
compute resource
constraints in a project at the pod and
container level, and specifies the amount of resources that a pod or container
can consume.
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.
apiVersion: "v1"
kind: "LimitRange"
metadata:
name: "resource-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)
-
The name of the limit range document.
-
The maximum amount of CPU that a pod can request on a node across all containers.
-
The maximum amount of memory that a pod can request on a node across all containers.
-
The minimum amount of CPU that a pod can request on a node across all containers.
-
The minimum amount of memory that a pod can request on a node across all containers.
-
The maximum amount of CPU that a single container in a pod can request.
-
The maximum amount of memory that a single container in a pod can request.
-
The minimum amount of CPU that a single container in a pod can request.
-
The minimum amount of memory that a single container in a pod can request.
-
The default amount of CPU that a container will be limited to use if not specified.
-
The default amount of memory that a container will be limited to use if not specified.
-
The default amount of CPU that a container will request to use if not specified.
-
The default amount of memory that a container will request to use if not specified.
-
The maximum amount of CPU burst that a container can make as a ratio of its limit over request.
Supported Resources:
-
CPU
-
Memory
Supported Constraints:
Per container, the following must hold true if specified:
Constraint | Behavior |
---|---|
|
If the configuration defines a |
|
If the configuration defines a |
|
If a configuration defines a For example, if a container has |
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.
Supported Resources:
-
CPU
-
Memory
Supported Constraints:
Across all containers in a pod, the following must hold true:
Constraint | Enforced Behavior |
---|---|
|
|
|
|
|
|
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> -n <project>
You can view any limit ranges defined in a project by navigating in the web console to the project’s Settings tab.
You can also use the CLI to view limit range details:
-
First, get the list of limit ranges defined in the project. For example, for a project called demoproject:
$ oc get limits -n demoproject NAME AGE resource-limits 6d
-
Then, describe the limit range you are interested in, for example the resource-limits limit range:
$ oc describe limits resource-limits Name: resource-limits Namespace: demoproject Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio ---- -------- --- --- --------------- ------------- ----------------------- Pod cpu 30m 2 - - - Pod memory 150Mi 1Gi - - - Container memory 150Mi 1Gi 307Mi 512Mi - Container cpu 30m 2 60m 1 -