Resource Quota

Refer to the official Kubernetes documentation: Resource Quotas

TOC

Understanding Resource Requests & Limits

Used to restrict resources available to a specific namespace. The total resource usage by all Pods in the namespace (excluding those in a Terminating state) must not exceed the quota.

Resource Requests: Define the minimum resources (e.g., CPU, memory) required by a container, guiding the Kubernetes Scheduler to place the Pod on a node with sufficient capacity.

Resource Limits: Define the maximum resources a container can consume, preventing resource exhaustion and ensuring cluster stability.

Quotas

Resource Quotas

If a resource is marked as Unlimited, no explicit quota is enforced, but usage cannot exceed the cluster's available capacity.

Resource Quotas track the cumulative resource consumption (e.g., container limits, new Pods, or PVCs) within a namespace.

Supported Quota Types

FieldDescription
Resource RequestsTotal requested resources for all Pods in the namespace:
  • CPU
  • Memory
Resource LimitsTotal limit resources for all Pods in the namespace:
  • CPU
  • Memory
Number of PodsMaximum number of Pods allowed in the namespace.

Note:

  • Namespace quotas are derived from the project's allocated cluster resources. If any resource's available quota is 0, namespace creation will fail. Contact the administrator.
  • Unlimited implies the namespace can consume the project's remaining cluster resources for that resource type.

YAML file example

# example-resourcequota.yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  name: example-resourcequota
  namespace: <example>
spec:
  hard:
    limits.cpu: "20"
    limits.memory: 20Gi
    pods: "500"
    requests.cpu: "2"
    requests.memory: 2Gi

Create resouce quota by using CLI

Create via YAML file

kubectl apply -f example-resourcequota.yaml

Create via command line directly

kubectl create resourcequota example-resourcequota --namespace=<example> --hard=limits.cpu=20,limits.memory=20Gi,pods=500

Storage Quotas

Quota Type:

  • All: Total PVC storage capacity in the namespace.
  • Storage Class: Total PVC storage capacity for a specific storage class.

Note: Ensure the storage class is pre-assigned to the project containing the namespace.

Extended Resources Quotas

Extended resource quotas are defined via ConfigMap. If the ConfigMap is missing, the resource category will not appear.

ConfigMap Field Descriptions

FieldDescription
data.dataTypeData type (e.g., vGPU).
data.defaultValueDefault value (empty = no default).
data.descriptionEnEnglish tooltip text (displayed when hovering over the field).
data.descriptionZhChinese tooltip text (displayed when hovering over the field).
data.excludeResourcesMutually exclusive resources (comma-separated).
data.groupResource group (e.g., MPS).
data.groupI18nGroup name in English/Chinese for UI dropdowns.
data.keySpecifies the value of the key. A configuration dictionary can only describe one key.
data.labelEn/data.labelZhThe English/Chinese name of the resource, which can be viewed and selected in the drop-down options corresponding to the quota types. This field serves the same function as the data.groupI18n field but is only applicable when the same resource has a single value, ensuring compatibility with the old version of the configuration dictionary (ConfigMap).
data.limitsIndicates whether to configure limits for the resources. Valid values include: disabled indicates limits cannot be configured for the resource, required indicates it must be input, and optional indicates it is optional input.
data.requestsIndicates whether to configure requests for the resources. Valid values include: disabled indicates requests cannot be configured for the resource, required indicates it must be input, optional indicates it is optional input, and fromLimits indicates it will use the same configuration as limits.
data.relatedResourcesAssociated resources. This field is reserved and currently cannot be used.
data.resourceUnitResource unit (e.g., cores, GiB). Not support input in Chinese.
data.runtimeClassNameRuntime class (default: nvidia for GPU).
metadata.labelsMandatory labels:
  • features.cpaas.io/type: CustomResourceLimitation
  • features.cpaas.io/group: <groupName>
  • features.cpaas.io/enabled: true or false, the label is mandatory and indicates whether it is enabled, default is true.
metadata.nameThe format is cf-crl-<*groupName*>-<*name*>, where
  • cf-crl is a fixed field and cannot be changed.
  • groupName is the name of the corresponding resource group, e.g., gpu-manager, galaxy, etc.
  • name is the resource name:
    • Resource name can be standard resource type names, e.g., cpu, memory, pods, etc. The standard resource names must comply with Kubernetes' qualified name rules and must exist within the defined standard resource types in Kubernetes.
    • Resource names can also be special resource types starting with specific prefixes, such as: hugepages- or requests.hugepages-.
metadata.namespaceMust be kube-public

Other Quotas

The format for custom quota names must comply with the following specifications:

  • If the custom quota name does not contain a slash (/): It must start and end with a letter or number, and can contain letters, numbers, hyphens (-), underscores (_), or periods (.), forming a qualified name with a maximum length of 63 characters.
  • If the custom quota name contains a slash (/): The name is divided into two parts: prefix and name, in the form of: prefix/name. The prefix must be a valid DNS subdomain, while the name must comply with the rules for a qualified name.
  • DNS Subdomain:
    • Label: Must start and end with lowercase letters or numbers, may contain hyphens (-), but cannot be exclusively composed of hyphens, with a maximum length of 63 characters.
    • Subdomain: Extends the rules of the label, allowing multiple labels to be connected by periods (.) to form a subdomain, with a maximum length of 253 characters.