Workloads
Init and sidecar containers
52 / 82

Order and lifecycle inside a Pod are guaranteed, not conventional.

Init containers run one at a time to completion before the app starts. Native sidecars start before the app and stop after it.

init: wait-for-dbloops until the database answersinit: run-migrationsruns only after the first succeedednative sidecar (restartPolicy: Always): log shipper or mesh proxystarts before the app, keeps runningmain app containerstarts only after every init containerhas succeededPod completionJob Pod completes when the maincontainer exits. The sidecar is stoppedafterwards and does not keep it Running.
pod spec
initContainers:
- {name: wait-for-db, image: busybox,
   command: [sh, -c, "until nc -z db 5432; do sleep 2; done"]}
containers:
- {name: log-shipper, image: fluent-bit, restartPolicy: Always}  # native sidecar
- {name: app, image: shopwave/checkout:1.4}

Why native sidecars exist

Before them, a log-shipper "sidecar" in a Job never exited, so the Job never completed. Marking it restartPolicy: Always inside initContainers (stable in recent Kubernetes versions; check your version) fixes ordering and completion.