Injecting Configurations from Multiple Files

Learn how to inject configuration from multiple files and from a directory.

Creating a ConfigMap from multiple files#

Let's see what happens when we execute the commands that follow.

Creating ConfigMap using two files

We created a ConfigMap with two files, and we created the same Pod based on the alpine.yml definition. Finally, we output the list of files from the /etc/config directory inside the Pod’s only container. The output of the latter command is as follows.

Config files inside container

We can see that both files are present in the container. That leads us to the conclusion that a ConfigMap can contain multiple files, and all will be created inside containers that mount it.

Deleting the objects#

Let’s delete the objects (again), and explore one more option behind the --from-file argument.

Deleting the ConfigMaps

Creating a ConfigMap from a directory#

The --from-file argument might lead you to the conclusion that you can specify only a file path as its value. It works with directories as well. We can, for example, add all files from the cm directory to a ConfigMap.

Creating ConfigMap from directory

We created my-config ConfigMap with the directory cm. Let’s describe it, and see what’s inside.

Desscribe ConfigMap

The output is as follows (content of the files is removed for brevity).

Names of all the configMaps

We can see that all six files from the cm directory are now inside the my-config ConfigMap.

We’re sure you already know what will happen if we create a Pod that mounts that ConfigMap. We’ll check it out anyways.

Create pod 'alpine.yml'

The output of the latter command is as follows.

List of files inside container 'alpine.yml'

All the files are there, and the time has come to move away from files and directories.

Deleting the objects#

So, let’s remove the objects first, and discuss the other sources.

Deleting ConfigMaps

Try it yourself#

A list of all the commands used in the lesson is given below.

Commands used in this Lesson

You can practice the commands in the following code playground by pressing the Run button and waiting for the cluster to set up.

/
cm
prometheus-conf.yml
my-env-file.yml
alpine-env.yml
alpine-env-all.yml
alpine.yml
prometheus.yml
Injecting configurations from multiple files
Injecting Configuration from a Single File
Injecting Configurations from Key/Value Literals
Mark as Completed
Report an Issue