Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

Make Kubernetes applications reliable in production

By updated

Improve this page

A Kubernetes deployment works when nothing goes wrong, but does it really survive maintenance, a saturated node or a load spike? Making it reliable means configuring the cluster and the workloads so that availability is guaranteed by design, not by luck.

Four mechanisms cover most of application reliability: PodDisruptionBudget objects for maintenance, anti-affinity for spreading replicas, probes to make the Pod lifecycle visible, and requests and limits for stable scheduling.

What you will learn

This page is an overview of the four settings that keep an application available. By the end, you will be able to:

  • explain what a PodDisruptionBudget protects during maintenance, and read one;
  • read an anti-affinity rule that spreads replicas across several nodes;
  • tell the readiness, liveness and startup probes apart;
  • explain why requests and limits matter for evictions;
  • find the lesson that teaches each setting in depth.

The 4 pillars of application availability

1. PodDisruptionBudget (PDB)

A PodDisruptionBudget guarantees that Kubernetes does not remove more than a given number of pods during a voluntary operation (drain, update). It does not protect against a sudden failure of a node: a failure is not a voluntary operation, and no budget can prevent it.

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: mon-app-pdb
spec:
minAvailable: 2 # or maxUnavailable: 1
selector:
matchLabels:
app: mon-app

2. Anti-affinity

Anti-affinity prevents several replicas of the same deployment from being placed on the same node, so a node failure does not take down the whole application.

affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: mon-app
topologyKey: kubernetes.io/hostname

The topologyKey says at what scale the replicas must be kept apart: with kubernetes.io/hostname, the unit of separation is the node. The requiredDuringScheduling... form is a strict rule: if no free node fits, the Pod stays Pending rather than share a node.

3. Health probes

Three probes watch a container, and each answers a different question:

  • Readiness: Kubernetes routes traffic to a pod only if it is ready to handle requests.
  • Liveness: Kubernetes restarts a stuck container, for example on a deadlock.
  • Startup: it avoids liveness false positives on a slow start. Until it succeeds, Kubernetes suspends the other two probes.

4. Requests and limits

requests define the resources guaranteed at scheduling time. limits cap consumption. A Pod without requests can be evicted at any time as soon as memory pressure appears on the node.

Where can you go deeper on each pillar?

This page gives the overview; each pillar has its own lesson in the course. The PodDisruptionBudget is practiced with the cordon, drain, uncordon cycle of preparing a maintenance (in French), where it shows its value. Anti-affinity and replica spreading belong to the lesson Affinities, taints and tolerations, probes to the lesson on probes, and requests and limits to their dedicated lesson.

The guide Application availability on Kubernetes (in French) then brings PodDisruptionBudget, anti-affinity and probes together in a single scenario, to check that service continuity holds when a node disappears.

Key takeaways

  • Without a PDB, a kubectl drain can evict all the replicas running on the node at once
  • Without anti-affinity, all your pods can land on the same node, and your deployment rests on a single point of failure
  • Without a readiness probe, Kubernetes routes traffic to a pod that is not ready yet
  • Without requests, the scheduler cannot guarantee the resources a pod needs, and evictions are unpredictable
  • Combining PDB, anti-affinity, probes and requests covers most of resilience with no extra infrastructure

Knowledge check

Check that you have grasped the essentials of this guide. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer