World map

 

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

You are here: cluster kind-dev namespace default
First the pod shows Init:0/2 while the prep step runs. Ten seconds later it is Running with READY 2/2. Terminal output: $ kubectl apply -f kedai.yaml pod/kedai created $ sleep 2 $ kubectl get pod kedai NAME READY STATUS RESTARTS AGE kedai 0/2 Init:0/2 0 2s $ sleep 10 $ kubectl get pod kedai NAME READY STATUS RESTARTS AGE kedai 2/2 Running 0 12s

An 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

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.

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

No trays here.

dev-workerOpen

No trays here.

dev-worker2Open

No trays here.

Time: +0s (sped up)

Predict

In noprep.yaml, the prep cook exits with an error. What does kubectl get pods show?

Pick one answer.

Check

You are here: cluster kind-dev namespace default
noprep shows Init:CrashLoopBackOff. The logs of the prep container say: where is the menu file. Terminal output: $ kubectl apply -f noprep.yaml pod/noprep created $ sleep 6 $ kubectl get pod noprep NAME READY STATUS RESTARTS AGE noprep 0/1 Init:CrashLoopBackOff 1 (3s ago) 6s $ kubectl logs noprep -c prep where is the menu file

Real 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.