Injecting Configurations from Key/Value Literals
Learn how to inject configurations from key/value literals.
We'll cover the following
Creating ConfigMap using literals#
Hopefully, even when our applications need different configs to work in distinct clusters, the differences are limited. Often, they should be limited to only a few key/value entries. In such cases, it might be easier to create ConfigMaps using --from-literal
.
Let’s take a look at an example.
The output of the latter command is as follows (metadata
is removed for brevity).
We can see that two entries were added, one for each literal.
Creating a Pod#
Let’s create a Pod with the ConfigMap mounted.
The output of the latter command is as follows.
Both files are there.
Verification#
Finally, let’s confirm that the content of one of the files is correct.
The output is as follows.
The
--from-literal
argument is useful when we’re in need to set a relatively small set of configuration entries in different clusters. It makes more sense to specify only the things that change, than all the configuration options.
The problem is that most of the existing applications are not designed to read separate configuration entries from different files.
On the other hand, if you’re sketching a new application, you might not choose this option either since you’d be able to develop it in a way that it reads environment variables. When faced with a choice between ConfigMap and environment variables, the latter wins most of the time.
All in all, we’re not sure how often you’ll be using the --from-literal
argument. Maybe a lot, more likely not at all.
Deleting the objects#
There’s one more config source left to explore, so let’s delete the objects we’re currently running, and move on.
That was it for injecting configuration from literals.
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.
/
- alpine.yml