Set Limit Range
The limit range (LimitRange) in namespaces is conducive to the rational allocation and management of resources, improving the utilization and availability of cluster resources. This document introduces how to set the limit range in namespaces. For more information, refer to LimitRange.
Prerequisites
- A K8S Cluster CCE has been created. For specific operations, refer to Create a K8S Cluster CCE.
- A namespace has been created. For specific operations, refer to Basic Operations of Namespaces.
Operation steps
- Log in to the Baidu AI Cloud management console.
- Navigate to Product Services - Cloud Native - Cloud Container Engine CCE, click Cluster Management - Cluster List, then click the target cluster name to enter the Cluster Details page. In the sidebar, click Namespace and Quota.
- In the namespace list, click More - Set Resource Limit Range for the target namespace.
- Configure CPU and memory limit ranges for the namespace.
| Limit name | Limitations |
|---|---|
| CPU request (request) | If a container does not declare a CPU limit, this is the minimum CPU usage per container request in the namespace |
| CPU limit (limit) | If a container does not declare a CPU limit, this is the maximum CPU usage per container request in the namespace |
| Memory request | If a container does not declare a memory limit, this is the minimum memory usage per container request in the namespace |
| Memory limit (limit) | If a container does not declare a memory limit, this is the maximum memory usage per container request in the namespace |
1> **Description:**
2> * Leaving a field blank indicates that there is no limit for that particular resource.
3> * ResourceQuota only applies to containers in Pods if the CPU and memory limits are specified in the ResourceQuota.
- Click OK to complete the setting of the namespace resource limit range.
Example
Use LimitRange to set default resources for containers
Create a LimitRange YAML to declare the default limit and request of container memory:
1apiVersion: v1
2kind: LimitRange
3metadata:
4 name: mem-limit-range
5 namespace: quota-example
6spec:
7 limits:
8 - default:
9 memory: 512Mi
10 defaultRequest:
11 memory: 256Mi
12 type: Container
If a Pod is created without declaring memory, this value will be set by default:
1 spec:
2 resources:
3 limits:
4 memory: 512Mi
5 requests:
6 memory: 256Mi
For more content, you can refer to: Limit Range via LimitRange
Use LimitRange to limit the ratio of limits/requests for containers
Description:
If the spec.limits.maxLimitRequestRatio field is defined in the LimitRange object, the request and limit of Pods/containers in the namespace cannot be 0, and the limit divided by the request must not exceed the spec.limits.maxLimitRequestRatio in LimitRange.
- Create a LimitRange YAML to declare the limit on the ratio of limits/requests in the namespace:
1apiVersion: v1
2kind: LimitRange
3metadata:
4 name: mem-limit-range
5 namespace: quota-example
6spec:
7 limits:
8 - maxLimitRequestRatio:
9 memory: 2
10 type: Container
- When creating a deployment using the following YAML, the Pod cannot be created because the maximum memory limit of the Pod exceeds twice the minimum memory request:
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: deployment-example
5 namespace: quota-example
6 labels:
7 app: nginx
8spec:
9 replicas: 1
10 selector:
11 matchLabels:
12 app: nginx
13 template:
14 metadata:
15 labels:
16 app: nginx
17 spec:
18 restartPolicy: Always
19 containers:
20 - name: nginx
21 image: hub.baidubce.com/cce/nginx-alpine-go:latest
22 imagePullPolicy: Always
23 resources:
24 limits:
25 cpu: 100m
26 memory: 1280Mi
27 requests:
28 cpu: 100m
29 memory: 128Mi
