Injecting Configurations from Environment Files

Learn how to use environment files to inject configurations.

Looking into the definition#

Let’s take a look at the my-env-file.yml file.

Contents of `my-env-file.yml`

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.

Create ConfigMap from `my-env-file.yml`

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).

Output of 'my-config'

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.

Output of creating Config from '--from-file'

For --from-file, first delete the previous config using kubectl 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.

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.

/
my-env-file.yml
Injecting configurations from Environment files
Injecting Configurations from Key/Value Literals
Converting ConfigMap Output into Environment Variables
Mark as Completed
Report an Issue