LimitRange
A LimitRange is a namespace-scoped Kubernetes policy that sets default, minimum, and maximum resource values for each container, pod, or PersistentVolumeClaim. It injects default requests and limits into pods that omit them and rejects pods that fall outside the allowed range.
LimitRange vs ResourceQuota
They are complementary. ResourceQuota caps the namespace total, while LimitRange constrains each individual object.
namespace total"] --> N["Namespace"] L["LimitRange
per container bounds"] --> N N --> P["Admitted pods"] classDef pol fill:#FFEDD5,color:#1E293B classDef ns fill:#DBEAFE,color:#1E293B classDef pod fill:#D1FAE5,color:#1E293B class Q,L pol class N ns class P pod
A production-grade LimitRange
apiVersion: v1kind: LimitRangemetadata: name: payments-container-limits namespace: payments-prodspec: limits: - type: Container defaultRequest: # injected when requests are missing cpu: "100m" memory: "128Mi" default: # injected when limits are missing cpu: "500m" memory: "512Mi" min: cpu: "50m" memory: "64Mi" max: cpu: "4" memory: "8Gi" - type: PersistentVolumeClaim min: storage: 1Gi max: storage: 100GiAuto-injection
When a pod omits resources, the LimitRange admission controller adds defaultRequest and default at creation time. The defaults apply only to missing fields, not to values the pod already specifies.
kubectl describe limitrange payments-container-limits -n payments-prodkubectl run test-pod --image=nginx -n payments-prodkubectl get pod test-pod -n payments-prod -o jsonpath='{.spec.containers[0].resources}'Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Pod rejected: exceeds max | Request or limit above max | Lower it or raise max |
| Pod rejected: below min | Value below min | Remove it and use defaults |
| OOMKilled after rollout | Default memory limit too low | Set explicit limits |
RememberLimitRange is per namespace and applies only to new objects. Existing pods are not changed.
Common MistakeSetting
defaultabovemax, ordefaultRequestabovedefault. Every pod without explicit resources is then rejected.
TipLimitRange is a friendly guardrail when onboarding teams to a shared cluster, because simple pod specs still get sane defaults.
Frequently Asked Questions
How do LimitRange and ResourceQuota interact?
A quota that tracks CPU or memory requires every pod to declare requests and limits. A LimitRange supplies defaults for pods that do not, and enforces per-container bounds, so the two together keep every pod accountable.
Why did a pod get resources I never wrote?
A LimitRange in the namespace injected defaults. Check kubectl describe limitrange, since the pod manifest will not show those values.
Does a LimitRange affect running pods?
No. It is enforced at admission, so only newly created or recreated pods are affected.