Kubernetes, patterns
Your Pod's Plus-One
A sidecar is a helper container riding in the same pod as your app. Here is what that actually means, how it is different from init containers, DaemonSets, and plain microservices, and a 30-second test for picking the right one.
A visual explainer. Kubernetes facts verified against the official docs. Sources at the end.
The short version
- A sidecar is a second container inside the same pod as your app. It shares the pod's network (so it talks to your app over localhost), its storage volumes, and its lifecycle.
- The name comes from motorcycle sidecars: bolted to the bike, goes where the bike goes, never rides alone.
- Kubernetes' own 2015 post named three multi-container patterns: the sidecar (extends the app), the ambassador (proxies localhost out to the world), and the adapter (translates the app's output into a standard shape).
- Since Kubernetes 1.33, sidecars are first-class citizens: an init container with restartPolicy: Always starts before your app, shuts down after it, and finally works in Jobs. (KEP-753)
01The motorcycle
A motorcycle sidecar is bolted to the bike. It goes where the bike goes, leans when the bike leans, and it never takes a trip on its own. The passenger gets the same view as the rider, the same wind, the same potholes.
A Kubernetes sidecar is the same deal. Your app is the motorcycle: the container with your code, serving traffic. The sidecar is a second container bolted to the same pod: a logging agent, a proxy, a metrics exporter. It sees the same network, reads the same files, and lives and dies on the app's schedule. Different vehicle, same physics.
Step through what that looks like inside a pod:
02Sidecar vs everything else
People mix up four things that all put "a helper near my app." They differ in where the helper lives, when it runs, and how it talks to your app. Tap through:
- Lives
- Inside your app's pod, as a second container.
- Runs
- The whole time the app runs.
- Talks
- Over localhost, plus shared volumes.
- Scales
- 1:1 with the pod, always. Five replicas means five sidecars.
- Reach for it
- When the helper needs the app's network, files, or lifecycle. Proxies, log shippers, config reloaders.
- Lives
- In the same pod.
- Runs
- Once, before the app starts. Must finish before anything else runs, then exits.
- Talks
- Leaves files in shared volumes for the app to find.
- Reach for it
- When the work is setup, not service. Waiting for the database, running migrations, fetching config.
- Lives
- One pod on every node, whether your app is there or not.
- Runs
- Always. It answers to the machine, not to any app.
- Talks
- Over the node network.
- Reach for it
- When the job belongs to the machine. Log collectors, monitoring agents, storage drivers.
- Lives
- In its own pods, scheduled anywhere in the cluster.
- Runs
- On an independent lifecycle. Deploys and restarts alone.
- Talks
- Over the cluster network, through a Service name.
- Scales
- On its own, by its own load.
- Reach for it
- When many apps share it, or it scales differently from any one app. Thumbnail APIs, databases, queues.
- Lives
- In the same container image, as a second process.
- Runs
- In the same process tree, tangled together.
- Talks
- Local files and function calls.
- Reach for it
- Almost never. Logs mix together, signals get lost, and updating the helper means rebuilding the whole image. One main process per container is the model for a reason.
03The three classic flavors
Back in 2015, the Kubernetes team wrote the post that named the multi-container patterns. "Sidecar" is the family name, but it has two famous siblings. All three ride in the same pod; they differ in which direction they face:
Their example: pair nginx with a container that syncs a git repo into a shared volume, and you get push-to-deploy. Write the syncer once, reuse it with Apache, Tomcat, anything. The helper makes the main container better at being itself.
Their example: a Redis cluster with one write master and many read replicas. The app just connects to localhost:6379, and the ambassador splits reads and writes to the right servers. The app never learns the cluster exists. In dev, you skip the ambassador and point at a real local Redis. Nothing changes.
Their example: ten apps export metrics ten different ways (JMX, StatsD, bespoke). One monitoring system wants one format. An adapter per pod reshapes each app's native output into the uniform model. Heterogeneous in, homogeneous out.
In practice, people call all three "sidecars." The purists will correct you, and now you know enough to nod along.
04Sidecars in the wild
The pattern is everywhere once you look. A few you have probably met:
Your app talks plain HTTP to localhost; the proxy adds mutual TLS, retries, and telemetry. This is the ambassador flavor at planetary scale, and it is why native sidecars mattered so much: the old model could not guarantee the proxy started first or stopped last.
Your app just writes files like it is 2005. The sidecar handles parsing, buffering, and delivery to wherever logs go to retire.
ConfigMap updated? The sidecar sees it and signals the app, no restart. Same pod, same files, zero downtime.
Your code opens a plain database connection; the proxy handles IAM authentication and encryption to the real Cloud SQL instance. The app stays dumb about credentials, which is exactly how you want it.
05The 30-second test
Five situations, five answers. Tap each card and check yourself:
Init container. It runs first, polls the database, and blocks the app until Postgres answers. Then it exits. Setup with an exit is the whole job description of an init container.
Sidecar. An Envoy proxy rides in the pod and terminates TLS on localhost. Your app keeps speaking plain HTTP and never knows the difference. This is the Istio and Linkerd move.
DaemonSet. The job is per machine, not per app. One pod per node, running whether your app is there or not.
Separate Deployment and Service. It is shared by many and scaled by its own load. A sidecar would pointlessly copy it five times, once per app.
Sidecar. A tiny reloader watches the mounted files and nudges the app over localhost. Same pod, same files, zero downtime.
If you got all five, the mental model has landed: match where the helper lives and when it runs to the problem, and the primitive picks itself.
06What it looks like in YAML
The classic shape. Two containers, one pod, one shared volume. The app writes logs like it is 2005; the sidecar ships them:
spec:
containers:
- name: app
image: myapp:2.0
volumeMounts:
- name: logs
mountPath: /var/log/app
- name: log-shipper
image: fluent/fluent-bit:3.2
volumeMounts:
- name: logs
mountPath: /var/log/app
readOnly: true
volumes:
- name: logs
emptyDir: {}
And the modern shape. Since Kubernetes 1.33, the officially blessed way to declare a sidecar is an init container with restartPolicy: Always. It starts before your app containers, shuts down after them, and unlike the old way, it no longer wedges Jobs open forever when the main work finishes:
spec:
initContainers:
- name: log-shipper
image: fluent/fluent-bit:3.2
restartPolicy: Always # this line makes it a native sidecar
volumeMounts:
- name: logs
mountPath: /var/log/app
containers:
- name: app
image: myapp:2.0
volumeMounts:
- name: logs
mountPath: /var/log/app
07Keep exploring
08Sources
- Kubernetes blog, "The Distributed System ToolKit: Patterns for Composite Containers" (2015). The original sidecar, ambassador, and adapter patterns, with the git-sync, Redis, and monitoring examples.
- Kubernetes blog, "Kubernetes v1.28: Introducing native sidecar containers" (2023). The restartPolicy: Always mechanism, startup and shutdown ordering, and why sidecars no longer block pod termination.
- KEP-753, "Sidecar containers". The full proposal: motivation (Jobs, log forwarding, service mesh), design, and the implementation history showing graduation to stable in 1.33.
- Kubernetes version numbers move fast; the 1.33 stable graduation is per the KEP's own implementation history. Pod networking and volume sharing semantics are per the core pods documentation.