Pattern principle: The sidecar pattern is named after the sidecar attached to the side of a motorcycle. The main application (the motorcycle) focuses solely on business logic, while the auxiliary functions (the passenger) are handled by the sidecar container. Because the two containers share the same network namespace and storage, they can communicate over localhost and share a file system.
Usage scenarios: The most representative use case is deploying an Envoy proxy as a sidecar in a Service Mesh (Istio, Linkerd). As all network traffic passes through the sidecar, mTLS encryption, traffic control, and observability are applied automatically. Log collection (Fluentd), configuration synchronization (Config Sync), and secret injection (Vault Agent) are also implemented as sidecars.
Advantages: Features can be added without modifying the application code. Because it is independent of language and framework, it provides consistent infrastructure functionality in a polyglot environment. Only the sidecar needs to be upgraded, so maintenance is easy, and the separation of concerns makes testing and debugging easier.
Disadvantages: The number of containers increases, which causes resource overhead. Managing the startup order among containers within a Pod is complex, and a sidecar failure can affect the main application. An additional network hop slightly increases latency.
Starting with Kubernetes 1.28, native sidecar containers are supported, which resolved the startup/shutdown order problem of sidecars combined with initContainer. Cloud vendors such as AWS App Mesh and Google Cloud Traffic Director also offer sidecar-based service meshes.