Avatar

Omnath Ganapure

Cloudsmith

Read Resume

Managing Configuration in Kubernetes: ConfigMaps & Secrets

3 min read
Article
Managing Configuration in Kubernetes: ConfigMaps & Secrets

When we deploy applications on Kubernetes, one big question comes up:

Where should configuration live?

Things like:

  • usernames

  • ports

  • environment values

  • database passwords

We should not hardcode these inside our application or Docker image. Kubernetes solves this problem using ConfigMaps and Secrets.

Today I learned :

  • What ConfigMaps and Secrets are

  • Why we need them

  • How I used them hands-on with a Node.js app

  • The difference between passing config as ENV vs Volume

Why separating code and configuration matters

If configuration is hardcoded:

  • Any small change requires rebuilding the image

  • Same image cannot be reused across environments

  • Secrets can leak into GitHub

Kubernetes allows us to inject configuration at runtime, without changing the image.

What is a ConfigMap?

A ConfigMap stores non-sensitive configuration data as key-value pairs.

Examples:

  • username

  • app mode (dev / prod)

  • feature flags

  • URLs

Example ConfigMap I created:

Managing Configuration in Kubernetes: ConfigMaps & Secrets

This data is not secret, so ConfigMap is the right choice.

Ways to use a ConfigMap in a Pod

There are two ways:

  • As environment variables

  • As files using volumes

Method 1: ConfigMap as Environment Variable

Managing Configuration in Kubernetes: ConfigMaps & Secrets

Inside the container:

Managing Configuration in Kubernetes: ConfigMaps & Secrets

Limitation

Environment variables are static.
If ConfigMap changes → Pod must restart.

Method 2: ConfigMap as a Volime - Better approach

Managing Configuration in Kubernetes: ConfigMaps & Secrets
Managing Configuration in Kubernetes: ConfigMaps & Secrets

After changing the username from configMap --> the username present in pod volume also changed

Managing Configuration in Kubernetes: ConfigMaps & Secrets

How my Node.js app reads the ConfigMap

Managing Configuration in Kubernetes: ConfigMaps & Secrets

This is a production-grade pattern.

The problem with ConfigMaps for passwords

ConfigMaps are stored:

  • In plain text

  • Visible to anyone with access

  • Not safe for passwords or API keys

That’s where Secrets come in.

What is a Kubernetes Secret?

A Secret is used for sensitive data like:

  • passwords

  • tokens

  • API keys

Secrets:

  • Are base64 encoded

  • Have stricter access control

  • Can also be injected as env or volume

Managing Configuration in Kubernetes: ConfigMaps & Secrets

Creating a Secret (the mistake I made)

Managing Configuration in Kubernetes: ConfigMaps & Secrets

Kubernetes rejected it.

Why?

data: expects base64, not plain text.

Managing Configuration in Kubernetes: ConfigMaps & Secrets

Kubernetes automatically converts it to base64.

Mounting Secret as a Volume (Recommended - Approach)

Managing Configuration in Kubernetes: ConfigMaps & Secrets
Managing Configuration in Kubernetes: ConfigMaps & Secrets

Reading Secret in Node.js

Managing Configuration in Kubernetes: ConfigMaps & Secrets

No env leaks. No hardcoding. Secure.

Key takeaways from this hands-on

  • ConfigMaps are for normal config

  • Secrets are for private data

  • Volume mounts are better than env

  • Kubernetes updates mounted files automatically

  • Application must read config from files

Share this article:
2026 — Built by Omnath Ganapure