Injecting Configurations from Environment Files
Learn how to use environment files to inject configurations.
We'll cover the following
Looking into the definition#
Let’s take a look at the my-env-file.yml
file.
The file has the same key/value pairs as those we used in the example with --from-literal
.
Creating the ConfigMap#
Let’s see what happens if we create a ConfigMap using that file as the source.
We created the ConfigMap using the --from-env-file
argument, and we retrieved the ConfigMap in yaml
format.
The output of the latter command is as follows (metadata
is removed for brevity).
We can see that there are two entries, each corresponding to key/value pairs from the file. The result is the same as when we created a ConfigMap using --from-literal
arguments. Two different sources produced the same outcome.
If we used --from-file
argument, the result would be as follows.
For
--from-file
, first delete the previous config usingkubectl delete cm my-config
.
All in all, --from-file
reads the content of one or more files, and stores it using file names as keys. --from-env-file
, assumes that content of a file is in key/value format, and stores each as a separate entry.
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.
/
- my-env-file.yml