Resource quotas and LimitRanges
Two gates: admission and scheduling
A bookstore team shares a cluster with other teams. It has a namespace called resource-study. The platform team wants to prevent one team from requesting all available capacity. A ResourceQuota caps the aggregate declared resources or object counts in that namespace. A LimitRange sets rules for individual allocations and can fill missing container resource settings. Neither policy adds a node. Admission decides whether an API request may be stored; the scheduler later decides whether a Pod can fit.
Read a namespace budget
Consider a CPU request quota of 4 cores, of which existing workloads have requested 3. A proposed Pod requesting 2 more cores would raise the total to 5; reject that request. A 1-core request reaches exactly 4 and fits this CPU quota dimension. It may still fail memory, count, limit or other admission rules. The following static manifest also caps aggregate CPU limits, memory requests and limits, and non-terminal Pod count. It assumes the namespace exists and quota admission is enabled. Do not apply it.
apiVersion: v1kind: ResourceQuotametadata: name: team-budget namespace: resource-studyspec: hard: requests.cpu: "4" requests.memory: 4Gi limits.cpu: "8" limits.memory: 8Gi pods: "10"Set individual defaults and bounds
The next policy sets default requests and limits for containers with omitted values and also defines minimum and maximum allocations. For a container with neither CPU nor memory settings, this example supplies requests of 250m and 128Mi and limits of 500m and 256Mi. If it explicitly asks for a CPU request of 1500m and has no limit, the default CPU limit of 500m is incompatible: a request cannot exceed its limit. Fix the declared settings rather than loosening the policy without review. If a limit is supplied without a request and no admission default supplies a request, Kubernetes uses the limit as the request. Multiple LimitRanges can make default selection unpredictable; prefer coordinated policy ownership.
apiVersion: v1kind: LimitRangemetadata: name: container-policy namespace: resource-studyspec: limits: - type: Container min: cpu: 100m memory: 64Mi max: cpu: "2" memory: 2Gi defaultRequest: cpu: 250m memory: 128Mi default: cpu: 500m memory: 256MiCalculate several dimensions before deciding
A namespace reports used requests of 3000m CPU and 3072Mi memory, used limits of 6000m CPU and 6144Mi memory, and 8 Pods. Adding a defaulted single-container Pod yields 3250m, 3200Mi, 6500m, 6400Mi and 9 Pods. These all fit the example quota. An 11th counted Pod fails even if CPU remains. Quota usage is declared accounting, not measured CPU or RAM; use status.used and status.hard as observations and consider concurrent requests. Existing workloads are not retroactively resized by a changed LimitRange. Lowering a quota does not evict existing Pods to make usage fit.
Investigate a rejected Pod safely
A controller such as a Deployment may be accepted while its attempt to create a Pod is denied. Inspect the controller events and quota state. In an explicitly approved disposable cluster, substitute the verified lab kubeconfig and context; commands here are static templates only. A 403 can also indicate authorization or other policies; read the actual reason. If a Pod exists but is Pending, inspect scheduling conditions before blaming quota.
kubectl --kubeconfig ./lab.kubeconfig --context resource-lab -n resource-study describe resourcequota team-budgetkubectl --kubeconfig ./lab.kubeconfig --context resource-lab -n resource-study describe limitrange container-policykubectl --kubeconfig ./lab.kubeconfig --context resource-lab -n resource-study get eventsPractice
Use admission-cases.json to decide whether each proposed request fits the recorded budget. Distinguish invalid container settings, quota denial and a later scheduling failure. Quotas do not enforce a cloud spending ceiling or isolate network traffic. Combine reviewed per-team budgets with access and network policies, monitoring and real capacity planning.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Resource quotas and LimitRanges — knowledge check
Apply resource-management concepts to offline scenarios.
The CPU request quota is 4 cores and 3 are used. A new Pod asks for 2 cores. What happens to this quota check?
What does a LimitRange defaultRequest specify?
A container requests 1500m CPU and receives a default limit of 500m. What is wrong?
A namespace quota has room, but no node has sufficient memory. What can occur?
What does a quota on pods constrain?