concept config in category kubernetes

appears as: config, config
Kubernetes in Action

This is an excerpt from Manning's book Kubernetes in Action.

But why are environment variables so popular in containers? Using configuration files inside Docker containers is a bit tricky, because you’d have to bake the config file into the container image itself or mount a volume containing the file into the container. Obviously, baking files into the image is similar to hardcoding configuration into the source code of the application, because it requires you to rebuild the image every time you want to change the config. Plus, everyone with access to the image can see the config, including any information that should be kept secret, such as credentials or encryption keys. Using a volume is better, but still requires you to make sure the file is written to the volume before the container is started.

If you’ve read the previous chapter, you might think of using a gitRepo volume as a configuration source. That’s not a bad idea, because it allows you to keep the config nicely versioned and enables you to easily rollback a config change if necessary. But a simpler way allows you to put the configuration data into a top-level Kubernetes resource and store it and all the other resource definitions in the same Git repository or in any other file-based storage. The Kubernetes resource for storing configuration data is called a ConfigMap. We’ll learn how to use it in this chapter.

Now, if you try hitting the server again with curl, you should see the response is no longer compressed (it no longer contains the Content-Encoding: gzip header). You’ve effectively changed the app’s config without having to restart the container or recreate the pod.