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
kind-dev namespace defaultA 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
Hint
Lower numbers first. Each one waits for Ready before the next starts.Predict
You delete web-1. What comes back?
Pick one answer.
Check
kind-dev namespace defaultLook 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.
kind-dev namespace defaultweb3/3 ready
dev-control-planeOpenManagerNo trays here.
dev-workerOpen- web-0
- web-2
dev-worker2Open- web-1
Hint
kubectl scale statefulset web --replicas=4, then kubectl get pods.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.
Bahasa Melayu
Pangkalan data anda ada 3 salinan. Salinan 0 ialah ketua; yang lain ikut. Selepas crash, ketua mesti kembali sebagai ketua. Nama rawak buat ini susah. Apa yang anda perlukan?
StatefulSet beri setiap dulang nombor yang kekal. Dulang bermula ikut giliran: web-0 dulu, kemudian web-1, kemudian web-2.
Bagaimana web bermula? Susun langkahnya.
Anda padam web-1. Apa yang kembali?
Lihat AGE. web-1 baru sahaja dibuat, tapi namanya kekal. Tempat duduk sama, dulang baharu.
Giliran anda. Tambah salinan keempat. Teka namanya sebelum anda lihat.
kubectl scale statefulset web --replicas=4, kemudian kubectl get pods.Deployment atau StatefulSet? Susun setiap satu.
Kini anda boleh jalankan pod dengan nama yang kekal, ikut giliran.
You finished this before. Practice is always welcome!
Official docs: Kubernetes: StatefulSets · Kubernetes: StatefulSet basics (tutorial)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?