Running workloadsLesson 7 of 14
Multi-container pods — init and sidecar (CKAD)
This covers "multi-container pod design patterns (e.g. sidecar, init and others)" and "persistent and ephemeral volumes" in the CKAD Application Design and Build (20%) domain. We follow in what order the containers in one pod start, and what they share. Sidecars injected automatically, like a service mesh proxy, are covered separately in Service Mesh ① Sidecars and Mutual Authentication.
Pod phasePending
Init done0/2
Running containersinit 1
RequestResponse / reportAppears in a later step
What you will learn
- Why init containers must finish one by one
- Where Init:CrashLoopBackOff comes from
- Start order of native sidecars (restartPolicy: Always)
- What containers in one pod share: network and volumes
Common exam questions
| Situation | What to do / command | Trap |
|---|---|---|
Pod shows Init:CrashLoopBackOff | Find which init failed with kubectl describe pod web, then kubectl logs web -c <init name> | The app container has not started, so it has no logs |
| Wait for the DB before the app | Put a waiting container in initContainers | In containers, it starts at the same time as the app |
| Add a log-collecting sidecar | Declare an emptyDir volume and mount it in both containers with volumeMounts | Mount it on only one side and the files are not visible |
| The sidecar must start before the app | Put it in initContainers with restartPolicy: Always | In containers, start order is not guaranteed |
| Two containers open the same port | Change one port | A pod shares one IP, so the ports collide |
Try it yourself
kubectl get pod web # STATUS like Init:0/2
kubectl get pod web -o jsonpath='{.spec.initContainers[*].restartPolicy}' # Always = native sidecar
kubectl describe pod web # Per-container state and mounts
kubectl logs web -c init-2 # Why the init container failed
kubectl logs web -c log-agent # Sidecar logs
Check yourself
Further reading: CNCF certification curriculum · Init containers · Sidecar containers · Volumes · Service Mesh ① Sidecars and Mutual Authentication