Kubernetes: scaling and running it well · senior
Init containers, sidecars and Jobs
Init containers run to completion before the app. A sidecar runs next to the app for its whole life. Native sidecars give the sidecar a start and stop order, and Jobs can finish.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Init containers run one after another to completion before the app starts. Right for fetching a file, waiting for a dependency or a one-time setup.
- A sidecar runs alongside the app for its whole life (log shipper, proxy, certificate refresher).
- Native sidecars, stable since Kubernetes 1.33, are init containers with restartPolicy: Always. They start before the app, keep running, can have probes, and stop after the app on shutdown.
- The old way (a sidecar as another normal container) had no ordering: the app could start before its proxy was ready, the log agent could die before the app flushed its last logs, and a Job never finished because the sidecar never exited.
- Use a Job for work that must finish, and a CronJob for schedules. Set backoffLimit, activeDeadlineSeconds and ttlSecondsAfterFinished.
- Database migrations as an init container run once per pod, so many pods race. A migration Job (or a pipeline step) runs once.
- Init containers add start time, so keep them short.
The red pen
Common traps: mistake → fix
Mistake: A sidecar is just another container in the pod
Fix: Without native sidecar support it has no start or stop order.
Mistake: A Job with a sidecar finishes when the main container exits
Fix: With old sidecars the Job hangs forever. Native sidecars solve it.
Mistake: Migrations in an init container are safe
Fix: Every pod runs them. Use one Job.
Easy to hard
Questions interviewers ask, easy to hard
- What is the difference between an init container and a sidecar?
- What is a native sidecar?
- Why did a Job never finish when it had a proxy container?
- Where would you run database migrations: init container, Job or app start?
- Design the pod for an API with a log shipper and a database proxy.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.