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-configNamespace: defaultLabels: <none>Annotations: <none>Data====prometheus-conf.yml:----global:scrape_interval: 15sscrape_configs:- job_name: prometheusmetrics_path: /prometheus/metricsstatic_configs:- targets:- localhost:9090Events: <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. ...