Microservice instances (Dockerized) with slightly different parameters in Kubernetes

5/13/2019

I’m somewhat new to Kubernetes and not sure the standard way to do this. I’d like to have many instances of a single microservice, but with each of the containers parameterized slightly differently. (Perhaps an environment variable passed to the container that’s different for each instance, as specified in the container spec of the .yaml file?)

It seems like a single deployment with multiple replicas wouldn’t work. Yet, having n different deployments with very slightly different .yaml files seems a bit redundant. Is there some sort of templating solution perhaps?

Or should each microservice be identical and seek out its parameters from a central service?

I realize this could be interpreted as an “opinion question” but I am looking for typical solutions.

-- vmayer
docker
kubernetes

2 Answers

5/15/2019

There are definitely several ways of doing it. One popular option is to use Helm. Helm lets you define kubernetes manifests using Go templates, and package them on a single unit called a Helm Chart. Later on you can install this Chart (install is what Helm calls to save these manifests in the Kubernetes API). When installing the Helm Chart, you can pass arguments that will be used when rendering the templates. That way you can re-use pretty much everything, and just replace the significant bits of your manifests: Deployments, Services, etc.

There are plenty of Helm charts available as open sources projects, that you can use as an example on how to create your own Chart.

And many useful guides on how to create your first Helm Chart.

Here you can find the official docs on developing your own Charts.

-- Jose Armesto
Source: StackOverflow

5/15/2019

As an option you can use StatefulSet with InitContainers plus ConfigMap.

Statefulset will guarantee you proper naming and order. ConfigMap will let you store fine-grained information like individual properties or coarse-grained information like entire config files.

Configuration data can be consumed in pods in a variety of ways. ConfigMaps can be used to:

1) Populate the values of environment variables

2) Set command-line arguments in a container

3) Populate config files in a volume

For the begging you can review Kubernetes – StatefulSets article where you can find a good explanation on how this pieces work together and inspect prepared example on how to deploy containers from the same image but with different properties.

-- VKR
Source: StackOverflow