Resource Quotas & Limit Ranges
Resource Quotas
ResourceQuotas provide constraints that limit aggregate resource consumption per namespace. They can limit:
- Compute resources (CPU, memory)
- Storage resources (PVC storage, PVC count)
- Object counts (pods, services, configmaps, etc.)
Example ResourceQuota
:
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
namespace: team-a
spec:
hard:
pods: "10"
requests.cpu: "4"
requests.memory: 8Gi
limits.cpu: "8"
limits.memory: 16Gi
This quota ensures that all pods in the “team-a” namespace:
- Cannot exceed 10 pods total
- Cannot request more than 4 CPU cores total
- Cannot request more than 8Gi memory total
- Cannot have limits exceeding 8 CPU cores total
- Cannot have limits exceeding 16Gi memory total
LimitRanges
LimitRanges define default, minimum, and maximum resource constraints for each object type in a namespace.
Example LimitRange
:
apiVersion: v1
kind: LimitRange
metadata:
name: default-limits
namespace: team-b
spec:
limits:
- default: # Default limits if not specified
cpu: 500m
memory: 256Mi
defaultRequest: # Default requests if not specified
cpu: 200m
memory: 128Mi
max: # Maximum allowed
cpu: 2
memory: 2Gi
min: # Minimum allowed
cpu: 100m
memory: 64Mi
type: Container
This LimitRange
in the “team-b” namespace ensures:
- All containers have default limits of 500m CPU and 256Mi memory if not specified
- All containers have default requests of 200m CPU and 128Mi memory if not specified
- No container can request/limit more than 2 CPU cores or 2Gi memory
- No container can request/limit less than 100m CPU or 64Mi memory