Sign In

Curriculum 19: Resource Management

ResourceQuotas Deep Dive

15 min · 25 XP

Resource Quotas Deep Dive

ResourceQuotas limit the total amount of resources that can be consumed within a namespace. They prevent any single team or application from monopolizing cluster resources.

Compute Resource Quotas

apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: team-alpha
spec:
  hard:
    requests.cpu: "10"
    requests.memory: "20Gi"
    limits.cpu: "20"
    limits.memory: "40Gi"
kubectl apply -f quota.yaml
kubectl get resourcequota -n team-alpha

Once applied, every pod in the namespace must specify resource requests and limits, or creation is rejected.

Object Count Quotas

Limit the number of specific objects in a namespace:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: object-quota
  namespace: team-alpha
spec:
  hard:
    pods: "50"
    services: "10"
    services.loadbalancers: "2"
    persistentvolumeclaims: "20"
    configmaps: "30"
    secrets: "30"

Checking Quota Usage

kubectl describe resourcequota compute-quota -n team-alpha

# Output shows used vs hard limits:
# Resource         Used   Hard
# requests.cpu     4      10
# requests.memory  8Gi    20Gi

Priority Class Quotas

Restrict resources by PriorityClass to control how much capacity goes to different workload tiers:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: high-priority-quota
  namespace: team-alpha
spec:
  hard:
    pods: "10"
    requests.cpu: "5"
  scopeSelector:
    matchExpressions:
      - scopeName: PriorityClass
        operator: In
        values: ["high"]

Multiple Quotas

A namespace can have multiple ResourceQuotas. All quotas are evaluated, and the most restrictive limit applies.

kubectl get resourcequota -n team-alpha

Combining compute quotas, object count quotas, and priority-based quotas gives administrators fine-grained control over namespace resource consumption.