Sidecar Pattern
Deploying a helper process alongside an application in the same pod to add capabilities such as proxies, log shipping, secrets or configuration without changing the app.
Intent
A sidecar is a separate container (or process) deployed with the main application, sharing its lifecycle, network namespace and optionally volumes. It extends the application with cross-cutting functionality written once and reused across languages.
Related patterns (from Brendan Burns' distributed systems patterns): ambassador (proxy for outbound calls) and adapter (normalize output, e.g. metrics format).
flowchart LR
subgraph Pod
APP[Application container] -- localhost --> SC1[Proxy sidecar<br/>mTLS, retries]
APP -- shared volume --> SC2[Log shipper sidecar]
SC3[Secrets agent sidecar] -- writes --> VOL[(Shared volume)]
APP --> VOL
end
SC1 --> NET[Other services]
SC2 --> LOGS[(Log backend)]Common sidecars
Envoy/mesh proxies, OpenTelemetry Collector agents, Fluent Bit log shippers, Vault Agent / secrets CSI drivers, Dapr runtime (building blocks for state, pub/sub, bindings), Cloud SQL Auth Proxy.
Kubernetes native sidecars
Kubernetes added native sidecar containers (init containers with restartPolicy: Always), stable since v1.33, so sidecars start before and stop after the main container, fixing long-standing ordering issues for jobs and shutdowns.
spec:
initContainers:
- name: otel-agent
image: otel/opentelemetry-collector:0.120.0
restartPolicy: Always # native sidecar
containers:
- name: app
image: registry.example.com/orders:1.4.2[!VERSION] Feature maturity and versions above change frequently; check the Kubernetes release notes for your cluster version.
Pros and cons
| Pros | Cons |
|---|---|
| Language-agnostic reuse of capabilities | Extra resource use per pod |
| Independent upgrades of helper functionality | More moving parts and startup ordering concerns |
| Keeps application code focused | Debugging across containers |
Interview questions
Sidecar vs library?
A library runs in-process with lower overhead and richer context but must exist per language and is upgraded with each app release. A sidecar is language-neutral and upgraded independently, at the cost of resources and an extra hop.