Set Resource Quota
The resource quota (ResourceQuota) of a namespace is used in scenarios where cluster resources are shared among multiple teams or users. It limits the total amount of resources that a team or user can use, including limiting the number of objects (containers and services) created under a namespace and the total amount of computing resources (CPU and memory) consumed. For more information, please refer to ResourceQuota.
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 Quota for the target namespace.
- Set up the computing limit range, storage limit range, and other limit parameters for the namespace.
| Limit name | Limitations |
|---|---|
| CPU request (request) | The upper limit of the total CPU requests of all non-terminated Pods in the namespace |
| CPU limit (limit) | The upper limit of the total CPUs of all non-terminated Pods in the namespace |
| Memory request | The upper limit of the total memory requests of all non-terminated Pods in the namespace |
| Memory limit (limit) | The upper limit of the total memory of all non-terminated Pods in the namespace |
| Total storage capacity | The upper limit of the total storage resource requests of all PVCs in the namespace |
| Total number of PVCs | The upper limit of the total number of PVCs allowed in the namespace |
| Local temporary storage request (request) | The upper limit of the total local temporary storage requests of all Pods in the namespace |
| Local temporary storage limit (request) | The upper limit of the total local temporary storage of all Pods in the namespace |
| Total number of Pods | The upper limit of the total non-terminated Pods in the namespace |
| Total number of services | The upper limit of the total number of services in the namespace |
| Total number of LoadBalancer services | The upper limit of the total number of LoadBalancer Services in the namespace |
| Total number of NodePorts used by services | The upper limit of the total number of NodePorts used by services in the namespace |
| Total number of deployments | The upper limit of the total number of deployments in the namespace |
| Total number of StatefulSets | The upper limit of the total number of StatefulSets in the namespace |
| Total number of jobs | The upper limit of the total number of jobs in the namespace |
| Total number of CronJobs | The upper limit of the total number of CronJobs in the namespace |
| Total number of secrets | The upper limit of the total number of secrets in the namespace |
| Total number of ConfigMaps | The upper limit of the total number of ConfigMaps in the namespace |
1> **Description:**
2> * Leaving a field blank indicates that there is no limit for that particular resource.
3> * Total number of NodePorts services used: This sets a limit on the number of NodePort resources available in the namespace, not the number of NodePort services.
- Click OK to complete the setting of the namespace resource quota.
Example
Limit the number of Pods in a namespace
This example illustrates the use of ResourceQuota to restrict the number of PersistentVolumeClaims that can be created in a namespace.
- Create an example namespace
1kubectl create namespace quota-example
- Create a ResourceQuota
Save the following yaml as quota-demo.yaml, and create the ResourceQuota by executing kubectl create -f quota-demo.yaml:
1apiVersion: v1
2kind: ResourceQuota
3metadata:
4 name: default-resource-quota
5 namespace: quota-example
6spec:
7 hard:
8 pods: "4" ## Maximum 4 Pods
9 configmaps: "10" ## Maximum 10 ConfigMaps
10 secrets: "10" ## Maximum 10 secrets
11 services: "10" ## Maximum 10 services
12 services.loadbalancers: "2" ## Maximum 2 Loadbanlacer-mode services
13 cpu: "1000" ## Maximum 1,000 CPU resources used in the namespace
14 memory: 200Gi ## Maximum 200 Gi memory resources used in the namespace
- Verify ResourceQuota
Create 5 Pods using the following YAML; but only 4 Pods will be created in the end:
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: deployment-example
5 namespace: quota-example
6 labels:
7 app: nginx
8spec:
9 replicas: 5
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: 128Mi
27 requests:
28 cpu: 100m
29 memory: 128Mi
A maximum of 4 Pods will be created:
1$kubectl get deployment -n quota-example
2NAME READY UP-TO-DATE AVAILABLE AGE
3deployment-example 4/5 4 4 59s
