Skip to content
Rahul Shishodiaon GitHub LinkedIn profile

Multi-Container Pods

Rule

  • Never put multiple microservices in one Pod: helpers/init only
  • Same Pod: shared localhost network + shared volumes

Init containers

  • Under spec.initContainers: run before app containers
  • Run sequentially; each must succeed before next
  • Failure → Pod restart, all inits re-run
  • Terminate when done; no probes
  • Status: Init:0/1Init:CrashLoopBackOffRunning
  • v1.35 native sidecar shape: init container with restartPolicy: Always
initContainers:
- name: configurer
  image: busybox
  command: ['sh', '-c', 'echo config > /usr/shared/app/config.json']
  volumeMounts: [{name: configdir, mountPath: /usr/shared/app}]
containers:
- name: web
  volumeMounts: [{name: configdir, mountPath: /usr/shared/app}]
volumes:
- name: configdir
  emptyDir: {}

Patterns comparison

PatternPurposeLifetime
InitSetup before appTerminates
SidecarHelper (logs, sync, watch)Full Pod life
AdapterTransform output for external systemsFull Pod life
AmbassadorProxy outbound calls (rate limit, auth)Full Pod life
  • Sidecar: e.g. monitor nginx error log via shared emptyDir
  • Adapter: transform app output (strip timestamps) without changing app code
  • Ambassador: app calls localhost:8081 → proxy handles external API

kubectl (multi-container)

kubectl logs <pod> -c <container>
kubectl logs <pod> -c <init-container>
kubectl exec <pod> -it -c <container> -- /bin/sh
kubectl get po <n>   # READY 2/2

Failures

SymptomCause
Stuck Init:*Init container failing: logs -c <init>

Exam tips

  • Without -c, kubectl targets first container in spec
  • Init failure restarts entire init chain: make logic idempotent
  • Shared files need both volumes[] and matching volumeMounts[] in each container