liveBook · Manning

Uptime

As explained in Kubernetes for Developers

High availability is the property of an application remaining operational despite failures of individual infrastructure components or failure domains.

A service can have several running copies and still go offline when one machine fails: if every copy is on that machine, the failure takes them all down. High availability means arranging those copies so the application can remain operational when an individual node—or even an availability zone—fails. In Kubernetes, that means using multiple Pod replicas and spreading them across failure domains. section 8.2.1 section 1.2

Two decisions work together:

  • Choose enough replicas. More Pods provide more redundancy, but use resources less efficiently. section 5.2.4
  • Place replicas apart. Spreading Pods across nodes avoids a single-node failure taking down every replica; spreading across zones can protect against a zone failure. section 5.2.4 section 1.2

Size replicas around a tolerable failure

Suppose a service needs 36 workers and users would not notice if six were offline. Concentrating no more than six workers in one Pod limits the impact of losing that Pod. Six Pods with six workers each provide redundancy, though more replicas can cost more resources. section 5.2.4

Listing 8.9 Chapter08/8.2.1_TopologySpread/deploy_topology.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: timeserver
spec:
  replicas: 3
  selector:
    matchLabels:
      pod: timeserver-pod
  template:
    metadata:
      labels:
        pod: timeserver-pod
    spec:
      topologySpreadConstraints:               #1
      - maxSkew: 1                             #2
        topologyKey: kubernetes.io/hostname    #3
        whenUnsatisfiable: ScheduleAnyway      #4
        labelSelector:                         #5
          matchLabels:                         #5
            pod: timeserver-pod                #5
      containers:
      - name: timeserver-container
        image: docker.io/wdenniss/timeserver:5
        resources:
          requests:
            cpu: 200m
            memory: 250Mi
#1 The topology constraint added
#2 The maximum number of replica imbalance
#3 The node label to use for the topology
#4 The behavior to use when it’s not possible to satisfy the topology requirement
#5 Another label selector set to this template’s metadata label

This three-replica Deployment specifies a topologySpreadConstraints rule using kubernetes.io/hostname. The setting asks Kubernetes to spread matching Pods across nodes rather than letting all three land together. Check that cluster nodes carry the label named by topologyKey; some platforms already provide default spreading policies. section 8.2.1

For a small deployment, start with the replicas and nodes you need rather than assuming a multizone setup is required. As availability needs grow, topology spread policies make the intended placement explicit. Kubernetes can also roll out service updates across zones; on a managed platform, gradual node replacement can migrate workloads to avoid downtime. section 1.2 section 8.2.1

How Kubernetes for Developers covers it

How deep it goes
Works through replica-sizing trade-offs and a Deployment topology-spread configuration, without defining a numerical uptime measure.
Examples
Uses a 36-worker replica-sizing scenario and a three-replica Kubernetes Deployment spread by node hostname.
What it assumes
Builds on containers and Pods as schedulable units, then uses their allocation to nodes to reason about availability.
What you can do after
Operate/configure it by choosing a replica count and setting topologySpreadConstraints when default Pod spreading is insufficient.
How it connects
Links high availability to Pod replicas, resource efficiency, topology spread constraints, nodes, availability zones, and rolling updates.

Also explained in

Compare how 20 books explain uptime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.