BM: Baca dalam Bahasa Melayu
World K2: Trays & Orders
Sidecars and init containers
You will learn: how to run a prep step before your app, and a helper beside it all day.
Checked with Kubernetes 1.37 on 31 Oct 2026
The problem
Your web server crashes at start. The menu file is not there yet. Something must lay it out first, then step aside. Who should do it?
Pick one answer.
Watch
kind-dev namespace defaultAn init container: The prep cook: runs before the app containers, finishes, then leaves. is the prep cook. It runs first, finishes, then leaves. Init:0/2 means 0 of 2 init containers are done. The web server waits for them.
Try it
How does the kedai tray start and stop? Put the steps in order.
First step at the top. Put these in order. Use the arrows, or drag.
- prep lays out the menu, then exits
- sweeper stops last
- Closing time: web stops first
- web starts serving
- sweeper starts and keeps running
Hint
Init containers run one by one, in the order the file lists them.Watch
A sidecar container: A helper on the same tray all day, like a log shipper. An init container with restartPolicy: Always. is a helper who stays all day, like a log shipper. It sits under initContainers. Which of its lines makes sweeper stay all day?
Pick one answer.
Try it
Your turn. Apply kedai.yaml. Watch STATUS change until READY says 2/2.
kind-dev namespace defaultdev-control-planeOpenManagerNo trays here.
dev-workerOpenNo trays here.
dev-worker2OpenNo trays here.
Hint
Typekubectl apply -f kedai.yaml, then kubectl get pods a few times.Predict
In noprep.yaml, the prep cook exits with an error. What does kubectl get pods show?
Pick one answer.
Check
kind-dev namespace defaultReal error: Init:CrashLoopBackOff. Plain words: the prep step keeps failing, so the tray never opens. Read its logs with -c prep.
You did it!
You can now add a prep step and an all-day helper to a pod.
Go deeper (optional)
Native sidecars are stable since Kubernetes 1.33. Older guides put helpers under containers:. Then a Job never finishes while its helper runs. A native sidecar does not hold a Job open.
Real rep (optional): on a throwaway cluster, apply kedai.yaml and watch it with kubectl get pod kedai -w.
Bahasa Melayu
Server web anda crash semasa mula. Fail menu belum ada. Sesuatu mesti sediakannya dulu, kemudian beredar. Siapa patut buat?
Init container (tukang persediaan) jalan dulu, siap, kemudian pergi. Init:0/2 maksudnya 0 daripada 2 init container sudah siap. Server web tunggu mereka.
Bagaimana dulang kedai bermula dan berhenti? Susun langkahnya.
Sidecar ialah pembantu sepanjang hari, contohnya penghantar log. Ia duduk bawah initContainers. Baris mana yang buat sweeper tinggal sepanjang hari?
Giliran anda. Apply kedai.yaml. Perhati STATUS berubah sehingga READY tunjuk 2/2.
kubectl apply -f kedai.yaml, kemudian kubectl get pods beberapa kali.Dalam noprep.yaml, tukang persediaan keluar dengan ralat. Apa kubectl get pods tunjuk?
Ralat sebenar: Init:CrashLoopBackOff. Maksudnya: langkah persediaan asyik gagal, jadi dulang tak pernah dibuka. Baca lognya dengan -c prep.
Kini anda boleh tambah langkah persediaan dan pembantu sepanjang hari pada pod.
You finished this before. Practice is always welcome!
Official docs: Kubernetes: Init containers · Kubernetes: Sidecar containers
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?