Kubernet Helm Concern

7/1/2021

You have a collection of pods that all run the same application, but with slightly different configuration. Applying the configuration at run -time would also be desirable. What's the best way to achieve this?

a: Create a separate container image for each version of the application, each with a different configuration

b: Use a single container image, but create ConfigMap objects for the different Configurations and apply them to the different pods

c: Create persistent Volumes that contain each config files and mount then to different pods

-- user16350039
kubernetes

1 Answer

7/1/2021

In my opinion, the best solution for this would be "b" to use ConfigMaps. Apply changes to the ConfigMap and redeploy the image/pod. I use this approach very often at work.

Edit from @AndD: ... ConfigMaps can contain small files and as such can be mounted as read only volumes instead of giving environment variables. So they can be used also instead of option c in case files are required.

My favorite command for this

kubectl patch deployment <DEPLOYMENT> -p "{\"spec\": {\"template\": {\"metadata\": { \"labels\": {  \"redeploy\": \"$(date +%s)\"}}}}}"

Patches a redeploy date to now in spec.template.metadata.labels.redeploy -> date +%s

Option "a" seems to be evenly good, the downside is you have to build the new Image, push it, deploy it. You could build a Jenkins/GitLab/whatever Pipeline to automate this way. But, I think ConfigMaps are fairly easier and are more "manageable". This approach is viable if you have very very many config files, which would be too much work to implement in ConfigMaps.

Option "c" feels a bit too clunky just for config files. Just my two cents. Best Practice is to not store config files in volumes. As you (often) want your Applications to be as "stateless" as possible.

-- bymo
Source: StackOverflow