Resource Quotas
Resource quotas prevent any single namespace from consuming more than its fair share of cluster resources. They enforce hard limits on compute usage and object counts.
What Is a ResourceQuota?
A ResourceQuota is a Kubernetes object that constrains the total resources a namespace can consume. Once a quota is in place, requests that would exceed it are rejected by the API server.
Setting Compute Quotas
Compute quotas limit CPU and memory across all pods in a namespace:
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-limits
namespace: development
spec:
hard:
requests.cpu: "4"
requests.memory: 8Gi
limits.cpu: "8"
limits.memory: 16Gi
kubectl apply -f compute-quota.yaml
With this quota active, every pod in the development namespace must declare resource requests and limits, or the API server will reject it.
Setting Object Count Quotas
Object count quotas cap the number of resources that can exist in a namespace:
apiVersion: v1
kind: ResourceQuota
metadata:
name: object-counts
namespace: development
spec:
hard:
pods: "20"
services: "10"
configmaps: "30"
secrets: "30"
persistentvolumeclaims: "5"
This prevents runaway resource creation from filling up a namespace.
Inspecting Quotas
Check what quotas are in place and how much has been consumed:
# List quotas in a namespace
kubectl get resourcequota -n development
# See detailed usage vs limits
kubectl describe resourcequota compute-limits -n development
The output shows Used versus Hard for each constrained resource, making it easy to spot when a namespace is approaching its limits.
Combining Multiple Quotas
You can apply multiple ResourceQuota objects to the same namespace. Kubernetes enforces all of them independently -- a request must satisfy every quota to succeed.
Key Takeaways
- ResourceQuotas enforce hard limits per namespace
- Compute quotas constrain total CPU and memory requests/limits
- Object quotas cap the number of pods, services, secrets, and other resources
- Pods must specify resource requests and limits when a compute quota is active
- Use
kubectl describe resourcequotato monitor usage against limits