Introduction
When working with Kubernetes, one of the most important practices is separating your application code from configuration data. In real-world projects, applications need different configurations depending on environments like development, testing, or production.
For example, your application may need:
Database connection strings
API keys
Environment-specific URLs
Instead of hardcoding these values inside your application, Kubernetes provides two powerful tools:
ConfigMap → for non-sensitive data
Secret → for sensitive data like passwords and tokens
In this article, we will understand how to use Kubernetes ConfigMap and Secret in a deployment step by step in simple words with practical examples.
What is a ConfigMap in Kubernetes?
A ConfigMap is used to store non-sensitive configuration data in key-value format.
Simple understanding
Think of ConfigMap as a settings file for your application.
Instead of writing configuration inside your code, you store it separately and Kubernetes injects it into your application when needed.
Example use cases
Application environment variables
App settings (like log level)
URLs and feature flags
What is a Secret in Kubernetes?
A Secret is used to store sensitive data securely.
Simple understanding
Think of Secret as a locked version of ConfigMap.
It stores:
Passwords
API keys
Tokens
Kubernetes encodes this data (base64) and allows controlled access.
Key Difference Between ConfigMap and Secret
ConfigMap → Non-sensitive data
Secret → Sensitive data
Both are used in a similar way inside deployments.
Step-by-Step: Using ConfigMap in Kubernetes Deployment
Let’s start with ConfigMap.
Step 1: Create a ConfigMap YAML File
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_ENV: production
APP_DEBUG: "false"
API_URL: "https://api.example.com"
What this means
data contains key-value pairs
These values will be injected into the container
Step 2: Apply ConfigMap to Kubernetes
Run this command:
kubectl apply -f configmap.yaml
Now your ConfigMap is created inside the cluster.
Join the conversation! Your thoughts help the community grow.