Mount config file or license file in Kubernetes

How to mount config file to container in Kubernetes

Many applications require configuration via some combination of config files, command line arguments, and environment variables. Kubernetes provides the configmap api to store configuration data which can be consumed by pods.

Limitation

Configmap or secrets can be consumed by pods in 2 ways. Using as files and using as values. In most cases, we’d like to let configmap be consumed as a whole file instead of a set of values by the application. To consume configmap or secrets as files in container, we need mount it as a volume to the container. for example,

In this case, if the mount path /etc/config already exists inside the container image, the configmap mount overlays the pre-existing contents. The folders and files under the path will be not accessible by application.

Solution

In most case, the application config file is sit with other files in the container. We can not simply create a mount path to mount the configmap to the container and overlay other files. When we build the image, we create a symbolic link for the config file or license file inside the container.