codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
☸️

Kubernetes

9 / 82 topics
9Managing Configuration with ConfigMaps10Handling Secrets in Kubernetes11Persistent Storage with Volumes12Implementing Network Policies
Tutorials/Kubernetes/Managing Configuration with ConfigMaps
☸️Kubernetes

Managing Configuration with ConfigMaps

Updated 2026-05-15
10 min read

Managing Configuration with ConfigMaps

Introduction

In Kubernetes, managing application configurations can be efficiently handled using ConfigMaps. A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume these ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.

ConfigMaps provide a way to separate configuration from code, making it easier to manage and update application settings without needing to rebuild container images. This tutorial will guide you through the basics of using ConfigMaps and then delve into some advanced concepts.

Concept

Creating a ConfigMap

A ConfigMap can be created in two ways: imperatively using kubectl or declaratively using a YAML file.

Imperative Approach

You can create a ConfigMap from literal values:

Terminal

Using a ConfigMap in a Pod

ConfigMaps can be used in Pods in several ways, including as environment variables or mounted as files.

As Environment Variables

You can inject the ConfigMap data into a Pod's environment variables:

YAML
1apiVersion: v1
2kind: Pod
3metadata:
4name: my-pod
5spec:
6containers:
7 - name: my-container
8 image: nginx
9 env:
10 - name: KEY1
11 valueFrom:
12 configMapKeyRef:
13 name: my-config
14 key: key1
15 - name: KEY2
16 valueFrom:
17 configMapKeyRef:
18 name: my-config
19 key: key2

As Files

You can also mount the ConfigMap as files in a volume:

YAML
1apiVersion: v1
2kind: Pod
3metadata:
4name: my-pod
5spec:
6containers:
7 - name: my-container
8 image: nginx
9 volumeMounts:
10 - name: config-volume
11 mountPath: /etc/config
12volumes:
13 - name: config-volume
14 configMap:
15 name: my-config

Examples

Example 1: Using ConfigMaps as Environment Variables

Let's create a simple Nginx Pod that uses a ConfigMap for its configuration:

  1. Create the ConfigMap:
YAML
1apiVersion: v1
2kind: ConfigMap
3metadata:
4name: nginx-config
5data:
6default.conf: |
7 server {
8 listen 80;
9 server_name localhost;
10
11 location / {
12 root /usr/share/nginx/html;
13 index index.html index.htm;
14 }
15 }
Terminal
  1. Verify the Pod is running:
Terminal

Now, you can access the Nginx server at http://localhost:8080.

Example 2: Using ConfigMaps as Files

Let's create a simple application that reads configuration from a file:

  1. Create the ConfigMap:
YAML
1apiVersion: v1
2kind: ConfigMap
3metadata:
4name: app-config
5data:
6config.json: |
7 {
8 "name": "My App",
9 "version": "1.0"
10 }
Terminal
  1. Verify the Pod is running:
Terminal
Output
{
"name": "My App",
"version": "1.0"
}

What's Next?

After mastering ConfigMaps, you might want to explore how to handle sensitive data using Secrets in Kubernetes. Secrets provide a way to manage sensitive information like passwords and tokens securely.

Stay tuned for more tutorials on advanced Kubernetes concepts!

Info

Remember, the key to effective configuration management is keeping your configurations separate from your codebase, allowing for easier updates and maintenance.

PreviousUsing Services in KubernetesNext Handling Secrets in Kubernetes

Recommended Gear

Using Services in KubernetesHandling Secrets in Kubernetes