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.
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.
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.
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.
We created my-config
ConfigMap with the directory cm
. Let’s describe it, and see what’s inside.
The output is as follows (content of the files is removed for brevity).
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.
The output of the latter command is as follows.
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.
Try it yourself#
A list of all the commands used in the lesson is given below.
You can practice the commands in the following code playground by pressing the Run button and waiting for the cluster to set up.
/
- prometheus-conf.yml