...

/

Injecting a Configuration from a Single File

Injecting a Configuration from a Single File

Learn to inject a configuration from a single file using the ConfigMap volume.

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.

Press + to interact
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.

Press + to interact
kubectl describe cm my-config

The output is as follows:

Press + to interact
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. ...