World map

 

BM: Baca dalam Bahasa Melayu

World K2: Trays & Orders

StatefulSets: names that stay

You will learn: how a StatefulSet gives pods names that stay, started in order.

Checked with Kubernetes 1.37 on 31 Oct 2026

The problem

Your database runs 3 copies. Copy 0 is the boss; the others follow it. After a crash, the boss must come back as the boss. Random names make that hard. What do you need?

Pick one answer.

Watch

You are here: cluster kind-dev namespace default
The StatefulSet web makes pods web-0, web-1 and web-2, one after another. Terminal output: $ kubectl apply -f web.yaml service/web created statefulset.apps/web created $ kubectl rollout status statefulset/web --timeout=180s Waiting for 3 pods to be ready... Waiting for 2 pods to be ready... Waiting for 1 pods to be ready... partitioned roll out complete: 3 new pods have been updated... $ kubectl get pods NAME READY STATUS RESTARTS AGE web-0 1/1 Running 0 9s web-1 1/1 Running 0 5s web-2 1/1 Running 0 1s

A StatefulSet: Trays with names that stay (web-0, web-1), started in order. For databases and other stateful apps. gives each tray a number that stays. The trays start in order: web-0 first, then web-1, then web-2.

Try it

How does web start? Put the steps in order.

First step at the top. Put these in order. Use the arrows, or drag.

  • web-0 starts
  • web-1 starts
  • web-0 is Ready
  • web-2 starts
  • web-1 is Ready

Predict

You delete web-1. What comes back?

Pick one answer.

Check

You are here: cluster kind-dev namespace default
web-1 is deleted. A new web-1 starts; its AGE is younger than web-0 and web-2. Terminal output: $ kubectl delete pod web-1 pod "web-1" deleted from default namespace $ kubectl wait --for=condition=Ready pod/web-1 --timeout=90s pod/web-1 condition met $ kubectl get pods NAME READY STATUS RESTARTS AGE web-0 1/1 Running 0 24s web-1 1/1 Running 0 1s web-2 1/1 Running 0 16s

Look at AGE. web-1 is brand new, but it kept its name. Same seat, new tray.

Try it

Your turn. Add a fourth copy. Guess its name before you look.

You are here: cluster kind-dev namespace default
Stalls: 3. Trays: 3 (3 ready). Waiting for a stall: 0.
  • web3/3 ready
dev-control-planeOpenManager

No trays here.

dev-workerOpen
  • web-0
  • web-2
dev-worker2Open
  • web-1
Time: +0s (sped up)

Check

Deployment or StatefulSet? Sort each one.

Drag a card into a box. Or tap the card, then tap the box.

      You did it!

      You can now run pods with names that stay, in order.

      Go deeper (optional)

      A StatefulSet needs a headless Service for steady addresses like web-0.web (World K3). It can give each tray its own storage with volumeClaimTemplates (World K4). Running a database yourself is real work. Many teams use a managed one.

      Real rep (optional): on a throwaway cluster, scale web down to 1. Watch which pods leave first.