Sub topic 1
Why replicas need to be spread out
Prerequisites
This chapter assumes you know the following:
- Pods, Deployments, labels and selectors.
- How to apply manifests and inspect resources with
kubectl. - Nodes carry labels, and a cluster may span several availability zones.
Replicas are not the same as availability
Setting replicas: 6 gives you six pods. It does not guarantee they run in different places. By default the scheduler picks nodes by free resources and affinity rules. It does not try to keep your replicas apart. All six pods can land on one node, or in one zone.
If that node or zone fails, every replica goes down together. The Deployment then has to recreate them elsewhere, and your service is unavailable until that finishes.
Failure domains
A failure domain is a group of machines that can fail together. Common examples:
- A node, which can crash or lose its network.
- A rack, which can lose power or a switch.
- An availability zone, which can have a data center outage.
- A region, which is rarely lost but possible.
Kubernetes expresses these domains as node labels. You can see the zone of each node like this:
kubectl get nodes -L topology.kubernetes.io/zoneSpreading replicas means that losing one domain removes only a fraction of your capacity. With six replicas across three zones, a zone outage leaves four running.
Two kinds of events, two features
Pods are lost in two different ways, and Kubernetes has a separate feature for each.
| Event | When it happens | Feature that helps |
|---|---|---|
| Placement | A pod is scheduled onto a node | Topology spread constraints |
| Voluntary eviction | An operator drains a node or upgrades the cluster | PodDisruptionBudget |
- Topology spread constraints act when the scheduler places a pod. They keep replicas balanced across domains.
- PodDisruptionBudgets act when someone asks to evict a pod on purpose. They limit how many replicas can be down at once.
Neither feature does the other's job. A well-spread Deployment with no budget can still lose all its pods in one drain. A budget with no spreading can still leave all your pods on one node.
What the rest of this tutorial covers
First you will learn topology spread constraints: the fields, how skew is calculated, and the limits of the feature. Then you will learn PodDisruptionBudgets: how drains use them, how to read their status, and which mistakes block maintenance. Finally you will combine both on one Deployment and troubleshoot the usual failures.
Exercise
A Deployment has four replicas, and all four run on one node in one zone. Which feature would have prevented this, and which feature limits how many pods an operator can evict during a drain?
Show answer
Topology spread constraints would have prevented the uneven placement, because they apply when the scheduler places pods. A PodDisruptionBudget limits how many pods can be voluntarily evicted during a drain.