Skip to main content
In this lesson we explore Kubernetes init containers. You will identify pods that use init containers, inspect their state, add an init container to a pod, and debug a failing init container. These tasks reinforce common operational workflows with kubectl and help you understand how init containers affect pod startup.
Quick tip: init containers always run to completion before regular containers start. They appear in kubectl describe pod under the “Init Containers” section — they do not contribute to the READY column in kubectl get pods.

1) Which pod has an init container?

List the pods:
At a glance green shows 2/2 (two regular containers) and blue shows 1/1, but kubectl get pods does not show init container information in the READY column. To inspect init containers, use kubectl describe pod <pod-name>. Describing red shows only regular containers:
Describing blue reveals an Init Containers: section, identifying blue as the pod with an init container:
Answer: the pod with an init container is blue.

2) What image is used by the init container on blue?

From the Init Containers: section:
  • Image: busybox
So the init container uses the busybox image.

3) What is the state and reason for the init container on blue?

From the Init Containers: details:
  • State: Terminated
  • Reason: Completed
  • Exit Code: 0
Explanation: the init container executed sleep 5 and exited normally (exit code 0). Init containers terminate when their task completes, after which the pod’s regular containers are started.

4) How many init containers does pod purple have? What is the pod state and how long until the application becomes available?

Check the pod status:
Describe purple:
  • Number of init containers: 2 (warm-up-1 and warm-up-2)
  • Pod state: Pending (because init containers are not finished)
  • Total initialization time: warm-up-1 (600s) + warm-up-2 (1200s) = 1800s (30 minutes)
Note: init containers run sequentially — the application container waits until all init containers complete. In real workloads, init containers perform tasks like migrations, configuration generation, or pre-warming caches.

5) Add an init container to red that sleeps for 20 seconds

Goal: add an init container named init-busybox that runs sleep 20 using the busybox image. Example pod manifest (save as red-pod.yaml and apply with kubectl apply -f or re-create as needed):
Apply the manifest:
After the init container completes (20 seconds) the pod’s main container will start and the pod will become Running.

6) Debugging a failing init container: pod orange

Initial symptom:
Describe shows the failing init container init-myservice:
Fetch the init container logs:
Root cause: a typo in the command (sleeep instead of sleep) causes the shell to return exit code 127 (command not found), which leads to Init:CrashLoopBackOff.
When an init container repeatedly fails, the pod remains in initialization state. Use kubectl describe pod <pod> to see the init container section and kubectl logs -c <init-container> to get its logs. Fix the command or image and reapply the manifest.
Fix the typo by editing the manifest or using kubectl edit pod orange and update the init container:
After applying the fix, the init container completes and the pod becomes Running:
Final pod status:
Summary: a small typo in an init container command can block pod startup and cause Init:CrashLoopBackOff. Diagnose with kubectl describe and kubectl logs -c <init-container>, then correct the manifest and reapply.

Quick reference table


End of lab solution.

Watch Video