Skip to main content
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
Pod webkubeletnode managerinit 1wait for DBinit 2fetch configlog-agentsidecarwebapp containeremptyDirshared volumeDBserviceConfig serverconfig filesLog storelog collectionstart #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​

SituationWhat to do / commandTrap
Pod shows Init:CrashLoopBackOffFind 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 appPut a waiting container in initContainersIn containers, it starts at the same time as the app
Add a log-collecting sidecarDeclare an emptyDir volume and mount it in both containers with volumeMountsMount it on only one side and the files are not visible
The sidecar must start before the appPut it in initContainers with restartPolicy: AlwaysIn containers, start order is not guaranteed
Two containers open the same portChange one portA 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

  1. The web pod shows Init:CrashLoopBackOff, and kubectl logs web -c web returns nothing. Why, and where should you look?
  2. A log-collecting sidecar must start before the app. Where do you declare it?
  3. web writes log files to an emptyDir, but log-agent sees no files. What is the most likely cause?

Further reading: CNCF certification curriculum · Init containers · Sidecar containers · Volumes · Service Mesh ① Sidecars and Mutual Authentication