Sidecar Containers Breakdown
- RNREDDY

- Sep 9
- 4 min read

Kubernetes Sidecar Containers Breakdown
While sidecar containers are widely talked about in the Kubernetes world, I’ve seen many engineers confuse them with init containers. Both run inside the same pod, but their purpose and behavior are not the same.
Init containers run before your main app starts. They finish one by one. If even one fails, your pod won’t start.

Real cases I’ve used:
Waiting for a MySQL database to become reachable using a curl or nc based script.
Copying static configuration files into a shared volume that the app will mount.
Pulling secrets from Vault, decoding them, and storing them into a mounted path.
Fixing volume permissions before the app mounts it as read-write.
They are ideal for blocking setup logic, especially when you want to isolate it in purpose built images rather than adding logic to the app itself.

Sidecars run alongside your app container and stay alive throughout the pod lifecycle. They share volumes and network with the app and are designed to offload operational work.
Real cases I’ve implemented:
A log shipper like Fluent Bit reading app logs from a shared volume and pushing to Loki.
A cert-refresh agent that talks to cert-manager and injects renewed TLS certs without restarting the app.
An Envoy proxy sidecar that adds mTLS, retries, and metrics in a service mesh setup.
A backup sidecar that syncs files to S3 every few minutes while the app keeps writing to disk.
The key here is that sidecars are not startup helpers. They are co-runners. They support the app at runtime by handling things the app shouldn’t be bothered with.
This difference is important before we move forward to understand:
Kubernetes Sidecar Architecture
Service Mesh Sidecar Use Case Example
How to Get the Best Out of Sidecars
1. Kubernetes Sidecar Architecture
To explain the sidecar pattern in depth, I’ve picked service mesh as the example. It’s one of the most real-world, high-impact use cases where sidecars shine.
In a service mesh, the sidecar is usually a network proxy like Envoy, injected into every pod. It works closely with a control plane that handles service discovery, certificates, routing rules, and identity mappings. Here's how it flows in practice.

It starts with namespaces.
You typically split responsibilities across two namespaces:
One for application pods with sidecars injected
One for the service mesh control plane
This separation makes security and lifecycle management easier. Your workloads stay isolated, while the control plane operates independently, watching and updating all sidecars.
Inside the app namespace, each pod has two containers.
The app container runs your actual microservice
The sidecar container is the proxy, injected automatically by the mesh
Both containers share:
A network namespace (they communicate over localhost)
A volume mount (used for sharing mTLS certs and tokens)
This setup ensures the sidecar can transparently handle all traffic without changing the app.
The control plane in the mesh namespace drives the system.
Register workloads and track them using a Workload Registry
Issue and rotate certs through a Certificate Issuer
Manage service identity and policy using an Identity Store
The control plane constantly watches for pod events and pushes updates to each sidecar. No manual restarts. No app changes. Everything flows from control to proxy.
Traffic never flows directly between apps.
When service A calls service B:
Service A’s app container sends traffic to localhost
Its sidecar encrypts the traffic with mTLS and forwards it
Service B’s sidecar receives it, decrypts it, verifies identity
Finally, it passes it to B’s app container over localhost
This ensures full encryption, observability, and access control for every call.
Secrets and identity are handled without app logic.
Sidecars receive mTLS material or tokens from the control plane and write them to a shared volume.
App containers simply read from that volume (no fetching, no refresh logic, no direct API calls to secret managers).
This model enforces least privilege and removes secrets management from app code entirely.
With just two namespaces, a shared volume, and a local proxy, Kubernetes sidecar architecture turns each pod into a secure, observable, policy-aware unit.
2. Service Mesh Sidecar Use Case Example

In a setup without sidecars, each application container is responsible for handling everything on its own. When one service needs to talk to another, it opens a direct connection.
That means the application must implement service discovery, retries, timeouts, and even TLS if encryption is needed. This leads to duplicated logic across services and tight coupling between business code and platform concerns. Any change in routing, security, or observability often requires code changes, retesting, and redeployment.

With sidecars in place, that responsibility shifts out of the application. The app container only talks to its local sidecar, using localhost. The sidecar takes care of outbound and inbound traffic, applies mutual TLS, handles retries, and collects metrics.
It reads identity and policy rules from the control plane, so traffic behavior can be adjusted centrally. The application remains focused on business logic, while the sidecar and mesh enforce platform-level guarantees.
3. How to Get the Best Out of Sidecars
In my experience, sidecars work best when teams treat them as part of the platform, not as an extension of the app.
Keep your app stateless so the sidecar can manage retries and failures smoothly
Use shared volumes only when the app and sidecar need to exchange files directly
Let the sidecar handle TLS, avoid adding certificate logic in your app
Push logs and metrics through the sidecar to keep your app clean and portable
Always automate sidecar injection using labels or annotations
Allocate separate CPU and memory for the sidecar to prevent resource contention
Watch for sidecar crashes since it brings down the whole pod
Validate mTLS behavior periodically using probes or test clients
Keep config updates centralized to avoid inconsistencies across pods
Use sidecars only when they provide continuous runtime value, not just boot-time convenience



Comments