Search⌘ K

Injecting a Configuration from a Single File

Explore how to create a Kubernetes ConfigMap from a single file and mount it within a Pod to manage application configurations. Understand how ConfigMaps store file data, how they are linked inside containers, and verify content consistency. Practice creating, using, and deleting ConfigMaps for flexible configuration management.

Creating a ConfigMap

In its purest (and probably the most common) form, a ConfigMap takes a single file. For example, we can create one from the prometheus-conf.yml file.

Shell
kubectl create cm my-config \
--from-file=prometheus-conf.yml

We create a ConfigMap (cm) called my-config. The data of the map is the content of the prometheus-conf.yml file.

Looking into the description

Let’s describe it and see what we get.

Shell
kubectl describe cm my-config

The output is as follows:

Shell
Name: my-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
prometheus-conf.yml:
----
global:
scrape_interval: 15s
scrape_configs:
- job_name: prometheus
metrics_path: /prometheus/metrics
static_configs:
- targets:
- localhost:9090
Events: <none>

The important part is located below Data. We can see the key which, in this case, is the name of the file (prometheus-conf.yml). Further down, we can see the contents of the file. ...