Kubernetes has the ability to set (in a deployment definition) environment variables from a config file. According to the Twelve Factor App guide, one should only store secrets/config vars in the environment variables, not in a file.
What are the arguments in support of using the Kubernetes ConfigMap to set environment variables?
I think the 12 Factor Guide should have worded that differently to avoid this confusion. The important aspect is that apps should "read" (instead of "store") config from the environment which is "a language and OS-agnostic standard".
ConfigMaps help accomplish this by mapping managed/versioned configuration to environment variables in a container.
The Twelve Factor App guide advocates the use of environment variables because when using configuration files
it’s easy to mistakenly check in a config file to the repo; there is a tendency for config files to be scattered about in different places and different formats, making it hard to see and manage all the config in one place. Further, these formats tend to be language- or framework-specific.
You could mount a ConfigMap
as a volume in your application's file system, but then your application is responsible of knowing how to read that file during the start up of the app. Normally, it's just easier to read environment variables passed when starting the application.
In both cases (reading from a file and reading from env vars) you would be following the Twelve Factor App recommendation. But when reading the configuration from a file, I believe is harder to run that application somewhere else, because it requires that we create that file first, which is a process that may be different for different platforms. On the other hand, passing environment variables it's usually always the same on all platforms.
Being able to easily run the application on different platforms is the key goal of the Twelve Factor App guide, so I'd choose directly passing environment variables from a ConfigMap
.