Setting quotas in namespaces
Quotas limit the consumption of resources in your project’s namespaces. Quotas are set at the namespace level and allow you to control the use of CPU, memory, storage, and GPU.
Getting started
Make sure that:
- You have the cluster or project administrator role.
- You have already created a project and a namespace. If not, create a project and a namespace.
Supported quota types
You can set the following quotas at the namespace level:
requests.cpu: Total requested CPU for pods in the namespace.requests.memory: Total requested memory for pods in the namespace.limits.cpu: Total CPU limit for pods in the namespace.limits.memory: Total memory limit for pods in the namespace.requests.storage: Total storage capacity for all PVCs in the namespace.requests.nvidia.com/gpu: Total number of GPUs for pods in the namespace.
If you set no quota for a certain resource type, no consumption limit will apply to this resource.
Creating a quota
Quotas are set at the project’s namespace level.
-
In the left-hand menu, select Projects.
-
Select the project from the list.
-
Click Namespaces on the project’s side panel.
-
Select the namespace.
-
Go to the Quotas tab.
-
Click + Add quota.
-
Specify the following quota settings:
- Quota name: Unique quota name in the namespace. This is a required field.
-
Under Resource quotas, add limits:
- Select the resource type from the Resource drop-down list, e.g.,
limits.cpu,requests.cpu. - Set the value in the Value field.
- To add another limit, click Add.
- To delete a row, click the recycle bin icon.
- Select the resource type from the Resource drop-down list, e.g.,
-
Optionally, expand the Additional section and specify a Scope, i.e., a YAML description of the quota's scope selector (e.g., for a limit based on pod priority class).
-
Click Save.
Create a manifest file, e.g., quota.yaml:
apiVersion: v1
kind: ResourceQuota
metadata:
name: my-quota
namespace: team-alpha-backend
spec:
hard:
limits.cpu: "20"
requests.cpu: "10"
limits.memory: "64Gi"
requests.memory: "32Gi"
scopeSelector:
matchExpressions:
- scopeName: PriorityClass
operator: In
values:
- middle
Where:
metadata.name: Quota name. This is a required field.metadata.namespace: Project namespace the quota is in. This is a required field.spec.hard: Dictionary of resources and their limits. This is a required field.spec.scopeSelector: Quota scope selector. This is an optional field.
Apply the manifest:
kubectl apply -f quota.yaml
Viewing the current quota usage
- In the left-hand menu, select Projects.
- Select the project from the list.
- Click Namespaces on the project’s side panel.
- Select the namespace.
- Go to the Quotas tab.
- Click the name of the quota.
The quota page displays the following:
- Quota information: Name, namespace, scope, creation date.
- Quotas: Table with the following columns: Resource, Requests (used/limit), Limits (used/limit), Effective.
To view the list of quotas in the namespace:
kubectl get resourcequota -n team-alpha-backend
Response example:
NAME REQUEST LIMIT AGE
my-quota requests.cpu: 0/2 limits.cpu: 0/4 20m
To view the quota's details with current usage data:
kubectl describe resourcequota my-quota -n team-alpha-backend
Response example:
Name: my-quota
Namespace: team-alpha-backend
Resource Used Hard
-------- ---- ----
limits.cpu 1 4
requests.cpu 1 2
Updating a quota
- In the left-hand menu, select Projects.
- Select the project from the list.
- Click Namespaces on the project’s side panel.
- Select the namespace.
- Go to the Quotas tab.
- In the quota row, click ⋯ and select Edit.
- Make your changes and click Save.
Edit the quota directly:
kubectl edit resourcequota my-quota -n team-alpha-backend
Note
If the new quota value is below the current usage level, the quota will be updated successfully. However, you will not be able to create new resources above the quota until your usage falls below the limit.
Deleting a quota
- In the left-hand menu, select Projects.
- Select the project from the list.
- Click Namespaces on the project’s side panel.
- Select the namespace.
- Go to the Quotas tab.
- In the quota row, click ⋯ and select Delete.
- Confirm the deletion.
kubectl delete resourcequota my-quota -n team-alpha-backend
Examples
Quota for a development environment
apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-quota
namespace: development-main
spec:
hard:
requests.cpu: "10"
requests.memory: "32Gi"
requests.storage: "200Gi"
limits.cpu: "20"
limits.memory: "64Gi"
Quota for a production namespace with GPUs
apiVersion: v1
kind: ResourceQuota
metadata:
name: ml-prod-quota
namespace: ml-production-main
spec:
hard:
requests.cpu: "100"
requests.memory: "512Gi"
requests.storage: "5Ti"
limits.cpu: "200"
limits.memory: "1Ti"
requests.nvidia.com/gpu: "8"