"Injecting" configuration files at startup

802 Views Asked by At

I have a number of legacy services running which read their configuration files from disk and a separate daemon which updates these files as they change in zookeeper (somewhat similar to confd).

For most of these types of configuration we would love to move to a more environment variable like model, where the config is fixed for the lifetime of the pod. We need to keep the outside config files as the source of truth as services are transitioning from the legacy model to kubernetes, however. I'm curious if there is a clean way to do this in kubernetes.

A simplified version of the current model that we are pursuing is:

  1. Create a docker image which has a utility for fetching config files and writing them to disk ones. Then writes a /donepath/done file.
  2. The main image waits until the done file exists. Then allows the normal service startup to progress.
  3. Use an empty dir volume and volume mounts to get the conf from the helper image into the main image.

I keep seeing instances of this problem where I "just" need to get a couple of files into the docker image at startup (to allow per-env/canary/etc variance), and running all of this machinery each time seems like a burden throw on devs. I'm curious if there is a more simplistic way to do this already in kubernetes or on the horizon.

1

There are 1 best solutions below

0
On

You can use the ADD command in your Dockerfile. It is used as ADD File /path/in/docker. This will allow you to add a complete file quickly to your container. You need to have the file you want to add to the image in the same directory as the Dockerfile when you build the container. You can also add a tar file this way which will be expanded during the build.

Another option is the ENV command in a your Dockerfile. This adds the data as an environment variable.