Topology and resource governance
Spread replicas across failure domains and make room in the namespace budget for releases.
What you will understand
- Explain how a topology key and a label selector determine which copies count toward spread.
- Use ResourceQuota to reason about how many requested copies admission will accept.
- Explain how a LimitRange changes the values on Pods that omit resources.
Builds on: Scheduling constraints
How Kubernetes spreads replicas across zones
Imagine a six-Pod API spread over three zones. If the zones have three, two, and one copy, some callers lose more capacity if the busiest zone fails. A topology spread constraint asks the scheduler to balance selected Pods across groups of nodes called topology domains. A node label might identify a zone, or the hostname label could make each node a separate domain. The selector tells the scheduler which Pods belong in the count.
In a simplified three-zone example with counts of two, two, and one, another Pod could bring them to two, two, and two. If the incoming Pod were placed in a zone already at two, its new count of three would differ from the minimum of one by two. A rule with maxSkew: 1 and DoNotSchedule would reject that placement in this example. Look for eligible domains in the scene before doing the arithmetic. Kubernetes accounts for options such as minDomains and which domains qualify under the rule.
Where can one more replica keep the zones balanced?
Count matching Pods in the eligible domains, then test where the next replica keeps the skew within the allowed bound.
Count catalog Pods per zone
- Zone eastSchedulercount 2
- Zone westSchedulercount 1
The selector counts api Pods, not every Pod in the namespace. The current eligible zone counts are east=2 and west=1.
Try the crowded zone
- New api PodZone east3 versus 1
Putting the new replica in east creates counts 3 and 1. Skew 2 exceeds the configured maximum 1.
Try the less crowded zone
- New api PodZone west2 versus 2
Putting it in west creates counts 2 and 2, so this topology constraint allows the placement.
Apply the remaining placement rules
- New api PodSelector counts app=api replicas
- SchedulerZone westbind new Pod
The scheduler can choose a fitting west node after all other resource and placement rules pass. Existing Pods do not move merely because this rule exists.
Two eligible zones with consistent labels; examples omit advanced minDomains and inclusion-policy settings.
Explore another case
Add a spread rule to a Deployment
Place the first fragment inside an existing Deployment’s spec.template.spec. Its own Pod template should carry app: api so that each new copy counts toward the distribution. Check the labels on the actual nodes first. The rule in the example uses zone labels, which may be missing in a small local cluster. For a local exercise, a comparable rule can reason about hostnames instead.
# Fragment: spec.template.spec of a Deployment labeled app=api
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: api
containers:
- name: api
image: nginx:1.27-alpine
resources:
requests: {cpu: 100m, memory: 64Mi}
limits: {cpu: 500m, memory: 128Mi}Budget for a rollout
A ResourceQuota limits aggregate quantities in a namespace. The example allows requests of one CPU and 1 GiB of memory, and up to ten counted Pods. A LimitRange can supply defaults and enforce per-object bounds. In this example it adds a request of 100m and 64Mi to a container that does not specify them. Apply quota and defaults in a disposable namespace so other workloads do not consume your budget.
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-budget
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
pods: "10"
---
apiVersion: v1
kind: LimitRange
metadata:
name: container-defaults
spec:
limits:
- type: Container
defaultRequest: {cpu: 100m, memory: 64Mi}
default: {cpu: 500m, memory: 256Mi}Ten copies at 100m use the full CPU budget. A Deployment trying to add an eleventh copy during a surge can be blocked by admission, even with room left on a node. Check ResourceQuota usage and ReplicaSet events to distinguish a rejected create from a Pod that exists but could not schedule. Try both constraints in the budget scene and the scheduling and quota lab.
When does an over-budget Pod get blocked?
Defaults can fill in resource requests. Namespace quota can reject a create before the scheduler starts looking for a node.
Request a new Pod
- Submitted PodAPI admissioncreate request
The submitted Pod has no CPU request, but admission has not yet completed.
Fill missing defaults
- LimitRangeAPI admissiondefault 100m
LimitRange supplies a 100m CPU request, changing the amount quota and scheduling must account for.
Compare against namespace quota
- API admissionResourceQuota1050m > 1000m
950m plus 100m exceeds the 1 CPU namespace quota. Admission rejects the Pod rather than leaving that Pod Pending.
Recheck when room is available
- ResourceQuota1 CPU hard; 800m already used before this create
- API admissionSchedulerpersisted Pod
After accounted requests fall sufficiently, a new create can pass quota. The scheduler still independently checks node capacity.
One namespace and one CPU request budget; real quotas can track many resources.
Inspect YAML or commands
Apply defaults
defaultRequest:
cpu: 100mFree budget then place
kubectl describe resourcequota team-budgetExplore another case
Check quota and node capacity
Quotas govern the resources admitted in a namespace. Requests still need to fit physical nodes, and spread or affinity rules can further restrict the eligible nodes. Plan capacity for old and new replicas to overlap when a rollout needs a surge. Adjust tight budgets deliberately rather than relying on an idle usage chart.
Check your understanding
A rollout stalls at ten Pods. There is no eleventh Pod to describe. Which object helps you discover why?
Inspect the new ReplicaSet’s events. If admission rejected its attempt to create the Pod, the event can report which quota the request exceeded. Compare that with namespace quota usage and any LimitRange defaults.
Primary documentation
Go to the source
Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise