0Pricing
DevOps Bootcamp · Lesson

ConfigMaps for Configuration

Externalize application configuration from container images using ConfigMaps.

ConfigMaps for Configuration is a free DevOps Bootcamp lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro to ConfigMaps

Applications often need configuration data, like database connection strings or feature flags.

Hardcoding this information directly into your container images can make them rigid and difficult to update.

ConfigMaps provide a way to externalize and centralize your application's non-sensitive configuration, keeping your images flexible.

What is a ConfigMap?

A ConfigMap is a Kubernetes object used to store non-sensitive data in key-value pairs.

Think of it as a central place for your application settings that can be accessed by your Pods.

  • Decouples config: Separates configuration from your application code.
  • Flexibility: Easily change settings without rebuilding images.
  • Portability: Move your app between environments with different configs.

Creating ConfigMaps: Imperative

You can quickly create a ConfigMap directly from the command line using kubectl create configmap.

This method is great for simple, one-off configurations or for quick testing.

Let's create a ConfigMap named my-app-config with a log level setting.

kubectl create configmap my-app-config \
  --from-literal=log_level=INFO

Inspecting Your ConfigMap

After creating a ConfigMap, you can view its details and verify its contents.

Use kubectl get with the -o yaml flag to see the full YAML definition, including the data stored within it.

kubectl get configmap my-app-config -o yaml

Declarative ConfigMap (YAML)

For production and version control, defining ConfigMaps using YAML manifests is the standard practice.

This approach makes your configurations reproducible and easy to manage alongside your application code.

Here's a YAML example for a game's configuration:

apiVersion: v1
kind: ConfigMap
metadata:
  name: game-config
data:
  game.properties: |
    level=easy
    player_limit=10
  ui.properties: |
    theme=dark
    language=en

Applying ConfigMap from YAML

To create the game-config ConfigMap, save the YAML content from the previous scene into a file (e.g., game-config.yaml).

Then, use kubectl apply -f to deploy it to your cluster.

# Save the YAML to game-config.yaml
kubectl apply -f game-config.yaml
kubectl get configmap game-config -o yaml

ConfigMaps as Environment Variables

One common way for a Pod to consume ConfigMap data is by injecting it as environment variables.

You can specify individual keys to be exposed or use envFrom to expose all key-value pairs from a ConfigMap.

This is ideal for simple application settings.

apiVersion: v1
kind: Pod
metadata:
  name: my-env-pod
spec:
  containers:
  - name: my-container
    image: busybox
    command: ["sh", "-c", "echo Log Level: $LOG_LEVEL && sleep 3600"]
    env:
    - name: LOG_LEVEL
      valueFrom:
        configMapKeyRef:
          name: my-app-config
          key: log_level

Demo: Pod with Env Config

Let's run the Pod definition to see the LOG_LEVEL environment variable in action.

Save the Pod YAML to env-pod.yaml, apply it, and then check the Pod's logs.

# Save Pod YAML to env-pod.yaml
kubectl apply -f env-pod.yaml
kubectl logs my-env-pod

# Clean up
kubeclt delete pod my-env-pod

ConfigMaps as Mounted Volumes

For applications that expect configuration files (e.g., nginx.conf, application.properties), you can mount a ConfigMap as a volume.

Each key-value pair in the ConfigMap becomes a file within the specified mount path inside the container.

apiVersion: v1
kind: Pod
metadata:
  name: my-volume-pod
spec:
  containers:
  - name: my-container
    image: busybox
    command: ["sh", "-c", "echo 'Contents of game.properties:' && cat /etc/config/game.properties && sleep 3600"]
    volumeMounts:
    - name: config-volume
      mountPath: /etc/config
  volumes:
  - name: config-volume
    configMap:
      name: game-config

Demo: Pod with Mounted Config

Now, let's deploy a Pod that mounts our game-config ConfigMap as a volume.

Save the Pod YAML to volume-pod.yaml, apply it, and inspect the logs to see the mounted file's content.

# Save Pod YAML to volume-pod.yaml
kubectl apply -f volume-pod.yaml
kubectl logs my-volume-pod

# Clean up
kubeclt delete pod my-volume-pod

Quick Check: ConfigMaps

Which of the following statements about Kubernetes ConfigMaps is true?

Recap: ConfigMaps

Great job! You've learned how ConfigMaps help manage configuration in Kubernetes:

  • Purpose: Store non-sensitive configuration data as key-value pairs.
  • Creation: Imperatively with kubectl create or declaratively with YAML.
  • Consumption: As environment variables or mounted files within Pods.
  • Benefit: Decouples configuration from application code, enhancing flexibility.

Next, we'll explore how to handle sensitive information securely using Kubernetes Secrets!

Frequently asked questions

Is the “ConfigMaps for Configuration” lesson free?

Yes — the full text of “ConfigMaps for Configuration” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “ConfigMaps for Configuration”?

Externalize application configuration from container images using ConfigMaps. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “ConfigMaps for Configuration” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. ConfigMaps for Configuration
  2. Secrets for Sensitive Data
  3. Persistent Volumes and Claims
  4. StorageClasses and Dynamic Provisioning
← Back to DevOps Bootcamp