
- The term derives from the motorcycle sidecar: an auxiliary unit attached to the main vehicle. In Kubernetes, a Pod can include one or more auxiliary containers alongside the main application container — these are called sidecars (or sidecar containers).
- Sidecars separate cross-cutting concerns (logging, metrics, proxying, configuration, etc.) from the business logic implemented in the main container.
Common use cases for sidecars
- Log forwarding and collection (Fluentd, Filebeat)
- Service proxies and filters (Envoy in a service mesh)
- Configuration or secrets synchronization
- Local caches, adapters, or translators that present a stable interface to the app
nginxis the primary application container and writes logs to/var/log/nginx.fluentdis a sidecar container that mounts the samenginx-logsvolume and forwards log data.emptyDiris used for example purposes; in production you would typically use a durable volume or stream logs directly to a logging backend.- Because both containers share the Pod network and storage, Fluentd can read files directly and communicate locally if needed.
Containers in a Pod share networking and storage, but they run as separate processes. Sidecars are a useful way to separate operational concerns (logs, metrics, proxying) from application code without changing the app itself.
- In a service mesh such as Istio, an Envoy proxy sidecar is injected into application Pods (either automatically or via mutation webhook). The Envoy sidecar intercepts and manages inbound and outbound traffic for the app, providing mTLS, retries, observability, and traffic shaping with no change to the application.
- Sidecar injection can be manual (add the container to manifests) or automatic (Istio mutating webhook). Automatic injection simplifies adoption but requires cluster-level configuration.
Remember: Pods are the lifecycle unit. If a Pod is deleted or restarted, all containers (application and sidecars) are affected. Design sidecars and storage choices (e.g., persistent volumes) with this in mind.
- Kubernetes Pods — official docs
- Istio service mesh (KodeKloud course)
- Envoy proxy official website
- Best practices: design sidecars to be stateless where possible and avoid introducing single points of failure by relying on durable storage or external services for critical data.