Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sidecar vs init container in kubernetes

I am having trouble distinguishing between a sidecar and an init container. So far, I understand that the real app containers wait for init container to do something. However, sidecar could do the same thing , could it not? And vice versa, init containers don't die off, so also run "on the side". Hence , my confusion.

Thanks for the help.

like image 677
Mamun Avatar asked Nov 15 '20 06:11

Mamun


People also ask

What is init container and sidecar container?

Init containers run before applications containers run in a pod, and sidecar containers run alongside application containers in a pod. One use for init containers is to bootstrap Appian with RDBMS/JDBC drivers not included in the Webapp Docker image (for example, MySQL or IBM Db2).

What is sidecar container in Kubernetes?

Sidecar containers are containers that are needed to run alongside the main container. The two containers share resources like pod storage and network interfaces. The sidecar containers can also share storage volumes with the main containers, allowing the main containers to access the data in the sidecars.

What is init container in Kubernetes?

This page provides an overview of init containers: specialized containers that run before app containers in a Pod. Init containers can contain utilities or setup scripts not present in an app image. You can specify init containers in the Pod specification alongside the containers array (which describes app containers).

What is Side Car in Docker?

Sidecar container is used to provide additional functionality to the application layer. Both the application container and the sidecar container are deployed on the same pod. Due to this arrangement both the containers share a number of resources like a local file system and network.

What is the difference between init and sidecar containers?

Init containers run before applications containers run in a pod, and sidecar containers run alongside application containers in a pod. One use for init containers is to bootstrap Appian with RDBMS/JDBC drivers not included in the Webapp Docker image (for example, MySQL or IBM Db2).

What are sidecars in Kubernetes?

Sidecar-Containers are a pattern to solve some use-cases. Usually, Kubernetes distinguishes between Init-Containers and Containers running inside your Pod. Typically, we call Sidecars all containers, that do not provide a user-focused service. For example, this could be a proxy or something for easier database access.

What is a sidecar in Docker?

A sidecar is just a container that runs on the same Pod as the application container. It shares the same volume and network as the main container, it can “help” or enhance how the application operates.

What is init container in Kubernetes?

Init containers are exactly like regular containers, except: Init containers always run to completion. Each init container must complete successfully before the next one starts. If a Pod's init container fails, the kubelet repeatedly restarts that init container until it succeeds.


1 Answers

Init-containers are used to initialize something inside your Pod. The init-containers will run and exit. After every init container which exits with a code 0, your main containers will start.

Examples for init-containers are:

  • Moving some file into your application containers, e.g. Themes or Configuration. This example is also described in the Kubernetes docs.

Kubernetes itself does not know anything about sidecars. Sidecar-Containers are a pattern to solve some use-cases. Usually, Kubernetes distinguishes between Init-Containers and Containers running inside your Pod.

Typically, we call Sidecars all containers, that do not provide a user-focused service. For example, this could be a proxy or something for easier database access. If you're running a Java-App you could use a sidecar to export JVM metrics in Prometheus format.

The difference here is, that your sidecar-containers must run all the time. If one of your not-init-containers exits, kubernetes will restart the whole pod.

And that's the difference.

  • Init containers run and exit before your main application starts
  • Sidecars run side-by-side with your main container(s) and provide some kind of service for them.
like image 132
alexzimmer96 Avatar answered Oct 09 '22 10:10

alexzimmer96