Search⌘ K

Defining ConfigMaps as YAML

Explore how to define Kubernetes ConfigMaps using YAML format, including structuring multi-line values and integrating ConfigMaps into deployments. Learn to deploy applications like Prometheus with ConfigMaps for flexible configuration management and confirm functionality through hands-on commands.

All ConfigMaps we created so far were done through kubectl create cm commands. Everything in Kubernetes can be defined as YAML, and that includes ConfigMaps as well.

Looking into the YAML

Even though we have not yet specified ConfigMaps as YAML, we have seen the format quite a few times throughout this chapter. Since we cannot be sure whether we can create a ConfigMap YAML file from memory, let’s make things easy for ourselves and use kubectl to output our existing my-config ConfigMap in YAML format.

Shell
kubectl get cm my-config -o yaml

The output is as follows:

YAML
apiVersion: v1
data:
something: else
weather: sunny
kind: ConfigMap
metadata:
name: my-config
...

Just as with any other Kubernetes object, ...