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: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:
blue reveals an Init Containers: section, identifying blue as the pod with an init container:
blue.
2) What image is used by the init container on blue?
From the Init Containers: section:
- Image:
busybox
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
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:
purple:
- Number of init containers: 2 (
warm-up-1andwarm-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)
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):
Running.
6) Debugging a failing init container: pod orange
Initial symptom:
init-myservice:
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.kubectl edit pod orange and update the init container:
Running:
Init:CrashLoopBackOff. Diagnose with kubectl describe and kubectl logs -c <init-container>, then correct the manifest and reapply.
Quick reference table
Links and references
- Kubernetes init containers concept: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
- kubectl reference: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
- Diagnosing pods and containers: https://kubernetes.io/docs/tasks/debug-application-cluster/debug-pod-replication-controller/
End of lab solution.