Multiple deployments or single deployment for similar containers

10/23/2017

I am running some Docker containers that share the same base image, but have slightly different values for a couple of environment variables (and a few shared values). My setup looks something like this:

# Run 2 containers for client 123
docker run --net=host -e CLIENT_ID=123 -e LOCATION=A -e SHARED_VALUE=ONE -ti myregistry.com/app:0.1.0
docker run --net=host -e CLIENT_ID=123 -e LOCATION=A -e SHARED_VALUE=ONE -ti myregistry.com/app:0.1.0

# Run 2 containers for client 456
docker run --net=host -e CLIENT_ID=456 -e LOCATION=B  -e SHARED_VALUE=ONE -ti myregistry.com/app:0.1.0
docker run --net=host -e CLIENT_ID=456 -e LOCATION=B  -e SHARED_VALUE=ONE -ti myregistry.com/app:0.1.0

... etc

I'm pretty sure that this would translate into multiple config maps, e.g.

configmaps

1)

# config map for the first set containers
apiVersion: v1
kind: ConfigMap
metadata:
  name: config-1
  namespace: default
data:
  CLIENT_ID: 123
  LOCATION: A

2)

# config map for the second set of containers
apiVersion: v1
kind: ConfigMap
metadata:
  name: config-2
  namespace: default
data:
  CLIENT_ID: 456
  LOCATION: B

3)

# shared configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: config-shared
  namespace: default
data:
  SHARED_VALUE=ONE

But what I'm unsure about is whether or not I should be creating separate deployments for these slightly different sets of containers, or if I should include both sets of containers in a single deployment. My inclination is to combine these into a single deployment like so:

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:

    - name: container-1
      ...
      env:
        - name: CLIENT_ID
          valueFrom:
            configMapKeyRef:
              name: config-1
              key: CLIENT_ID
        - name: LOCATION
          valueFrom:
            configMapKeyRef:
              name: config-1
              key: LOCATION
        - name: SHARED_VALUE
          valueFrom:
            configMapKeyRef:
              name: config-shared
              key: SHARED_VALUE


    - name: container-2
      ...
      env:
        - name: CLIENT_ID
          valueFrom:
            configMapKeyRef:
              name: config-2
              key: CLIENT_ID
        - name: LOCATION
          valueFrom:
            configMapKeyRef:
              name: config-2
              key: LOCATION
        - name: SHARED_VALUE
          valueFrom:
            configMapKeyRef:
              name: config-shared
              key: SHARED_VALUE

Anyways, what kinds of things should I be considering when deciding whether or not to include multiple containers inside a single deployment? Are there downsides to the approach I'm taking here?

-- jerry
kubernetes

2 Answers

10/23/2017

You can use configMap to populate the value of environment variables and refer it in your pod definition. You approach is good.

Regarding deploying multiple container in a pod, it depends of the degree of interdependence between your container. Kubernetes documentation is well written about How Pods manage multiple Containers.

Note if you want to couple containers in a single pod, I advice you to use Kubernetes Deployments object to take advantage of ReplicaSets and pods collectively.

-- Nicolas Pepinster
Source: StackOverflow

10/23/2017

Separate deployments per client is definately the way to go in this case in my opinion.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow