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
... etcI'm pretty sure that this would translate into multiple config maps, e.g.
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=ONEBut 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_VALUEAnyways, 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?
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.
Separate deployments per client is definately the way to go in this case in my opinion.