Search⌘ K
AI Features

Extracting Configs to a ConfigMap

Explore how to use ConfigMaps in Kubernetes to manage application configurations across different environments. Understand how to create ConfigMaps, inject individual or multiple environment variables, and avoid conflicts by using prefixes. This lesson helps you efficiently manage container configurations without duplicating manifests.

ConfigMap

If we want to run this same application in multiple different environments, like staging and production, we would need to have two copies of this manifest just to change the value of these environment variables. This is one of the problems with embedding these environment variables in the manifest.

Luckily, Kubernetes has a high level resource called ConfigMap that serves this purpose. It’s basically a place for us to store key-value pairs that can be injected into our containers when they run. Let’s see an example.

R
# hellok8s-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: hellok8s-config
data:
MESSAGE: "It works with a ConfigMap!"

Once ...