Resource Quota in Kubernetes: 7 amazing steps Complete Guided

What is a Resource Quota in Kubernetes?

In Kubernetes, it is a policy object that enforces limits on the total amount of cluster resources that a namespace can consume. It helps prevent a single team, application, or user from monopolizing resources, which is essential in shared or production environments.

  • Compute resources (CPU and memory)

  • Storage resources (PVCs, ephemeral storage)

  • Object counts (number of Pods, Services, Secrets, etc.)

Think of it as a “budget” for each namespace—you assign a fixed limit of resources, and the namespace can’t exceed it.

 Uses

Let’s say your Kubernetes cluster is shared by multiple teams. Without restrictions, one team could spin up hundreds of pods, hogging the CPU and RAM, leaving nothing for others. This leads to:

  • Pod scheduling failures

  • Application downtime

  • Cluster instability

 benefits

  • Prevent resource exhaustion

  • Enforce multi-tenancy rules

  • Ensure fair usage

  • Support cost control and chargebacks

  • Maintain cluster reliability

In large organizations, Resource Quotas are not optional—they’re essential.

How Resource Quota Works in Kubernetes

  • Applied per namespace

  • Enforced at the API server level

  • Work in conjunction with Limit Range (per-pod/container limits)

  • Deny creation of resources that would exceed quota

The Kube API server checks every request against the namespace’s . If a request exceeds any  (like too many pods, too much CPU), it gets rejected with an error.

1. Computer Resources

  • requests.cpu, limits.cpu

  • requests.memory, limits.memory

2. Storage Resources

  • requests.storage (PVC storage)

  • persistentvolumeclaims (count)

  • ephemeral-storage

3. Object Count Resources

  • pods, services, replicationcontrollers

  • secrets, configmaps

  • deployments, jobs, ingresses (with extensions)

4. Extended Resources

  • GPU limits (e.g., nvidia.com/gpu)

  • Custom-defined resources via device plugins

 Example

Let’s start with a basic Resource Quota that limits CPU, memory, and object counts in a dev-team namespace:

apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-quota
namespace: dev-team
spec:
hard:
pods: "20"
requests.cpu: "4"
limits.cpu: "10"
requests.memory: "8Gi"
limits.memory: "20Gi"
persistentvolumeclaims: "5"

Explanation:

  • Allows only 20 pods in total

  • CPU requests must not exceed 4 cores

  • CPU limits capped at 10 cores

  • Memory requests and limits controlled at 8Gi and 20Gi

  • PVCs limited to 5 per namespace

 How to Create and Use a Resource Quota in Kubernetes

 Step-by-Step Implementation

1. Create the Namespace

kubectl create namespace dev-team

2. Apply the Resource Quota YAML

Save your YAML as resource-quota.yaml and run:

kubectl apply -f resource-quota.yaml

3. Check the Resource Quota Status

kubectl get resource quota -n dev-team
kubectl describe resource quota dev-quota -n dev-team

You’ll see the used vs. allowed resources, which helps you track usage and debug limits.

Common Issues

 1. Pod Creation Fails Unexpectedly

  • Error: pods "xyz" is forbidden: exceeded quota

  • Reason: New pod would push usage over the allowed limit

  • Fix: Adjust quota or scale down existing workloads

 2. No Resource Requests Defined

  • Pods created without requests.cpu or requests.memory may be rejected

  • Solution: Define a Limit Range to enforce default values

resource quota

 

 

  Using Limit Range with Resource Quota

While  limits total usage per namespace, Limit Range ensures each container/pod declares its own resource requests/limits.

Example Limit Range YAML:

apiVersion: v1
kind: LimitRange
metadata:
name: default-limits
namespace: dev-team
spec:
limits:
- default:
cpu: 500m
memory: 512Mi
defaultRequest:
cpu: 200m
memory: 256Mi
type: Container

This ensures all containers get default resource assignments, making quota enforcement predictable.

 Monitoring Quota Usage

To track quota usage, run:

kubectl describe resourcequota dev-quota -n dev-team

Sample output:

Resource Used Hard
-------- ---- ----
pods 10 20
requests.cpu 3 4
limits.cpu 6 10
requests.memory 5Gi 8Gi
limits.memory 12Gi 20Gi

You can also visualize usage via:

  • Lens IDE

  • Prometheus & Grafana

  • Kubernetes Dashboard

 Use Cases of Resource Quota

Use Case Benefit
Multi-team Kubernetes Enforces fairness, avoids conflicts
CI/CD environments Prevents test jobs from consuming too much
AI/ML workloads with GPUs Controls expensive GPU allocation
Cost optimization Avoids resource wastage
Dev/Test/Prod separation Apply different limits for each stage

Conclusion

It is a cornerstone for effective multi-tenant cluster management in Kubernetes. It enforces limits on resource consumption at the namespace level, helping teams coexist fairly and keeping the cluster stable.

When combined with Limit Range and good monitoring practices,it help you scale Kubernetes clusters responsibly, reduce costs, and improve cluster.

More about blogs: Click here