https://www.techtarget.com/searchapparchitecture/tip/The-reasons-to-use-or-not-use-sidecars-in-Kubernetes
Kubernetes introduced sidecar containers to solve a fundamental challenge: When you deploy an application via Kubernetes, it can be difficult to directly integrate that application with the various external monitoring tools, logging systems and other components often readily available to developers working with conventional servers.
The sidecar container approach addresses this problem by running an application's core processes inside its own Kubernetes pod instance, while a companion pod running alongside it facilitates access to external resources and communication with external systems. In other words, using sidecars in Kubernetes can let you have your cake and eat it, too.
The key to making this approach work, however, is understanding exactly how, why and when to use a sidecar container. Let's examine some of the key benefits and drawbacks of the sidecar container approach and review some guidelines that can help you decide if it's the right move.
In Kubernetes, the sidecar container approach is primarily a method used to cut through otherwise interfering abstractions. In cases like this, they offer several important advantages:
Of course, using sidecars in Kubernetes isn't a free ride. Here are some of the notable pitfalls associated with sidecar containers:
Sidecar containers are not the only way to build a tunnel through the Kubernetes abstraction layer. The most obvious option, of course, is to add whichever extra functionality you need directly to the application container itself -- provided that isn't a detriment to performance. Similarly, you can configure your overarching software network so that the application can interact with external software and tools via the network itself.
In many cases, it's also possible to add managing components like DaemonSets to each Kubernetes node to perform tasks that can't process inside individual containers.
In general, most teams that manage Kubernetes clusters of significant size and complexity will eventually rely on sidecar containers. Thus, sidecars have become a go-to solution for cutting through the abstraction that Kubernetes imposes between pods and the rest of the world. However, they don't come without their drawbacks, so development teams need to think carefully before deploying sidecars at will.
In order to decide if a sidecar is the right approach, ask yourself the following questions:
28 May 2021