This is one of the most important Kubernetes basics, used in real microservices deployments.
You will learn:
✔ Create a ConfigMap
✔ Inject values into a Pod as environment variables
✔ Verify inside the container
✔ Update ConfigMap and see Pod behavior
🟩 Step 1 — Create a ConfigMap
Create app-config.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-config
data:
APP_ENV: "development"
APP_VERSION: "1.0.0"
WELCOME_MESSAGE: "Hello from ConfigMap!"
Apply it:
kubectl apply -f app-config.yaml
Check it:
kubectl get configmaps demo-config -o yaml
🟩 Step 2 — Create a Pod That Uses the ConfigMap
Create pod-configmap-demo.yaml:
apiVersion: v1
kind: Pod
metadata:
name: configmap-demo-pod
spec:
containers:
- name: demo-container
image: busybox
command: ["sh", "-c", "sleep 3600"]
env:
- name: ENVIRONMENT
valueFrom:
configMapKeyRef:
name: demo-config
key: APP_ENV
- name: VERSION
valueFrom:
configMapKeyRef:
name: demo-config
key: APP_VERSION
- name: MESSAGE
valueFrom:
configMapKeyRef:
name: demo-config
key: WELCOME_MESSAGE
Apply:
kubectl apply -f pod-configmap-demo.yaml
Wait until ready:
kubectl wait --for=condition=Ready pod/configmap-demo-pod --timeout=60s
🟩 Step 3 — Verify Environment Variables Inside the Pod
Exec inside the Pod:
kubectl exec -it configmap-demo-pod -- sh
Inside container:
echo $ENVIRONMENT
echo $VERSION
echo $MESSAGE
Expected output:
development
1.0.0
Hello from ConfigMap!
Exit:
exit
🟩 Step 4 — Update the ConfigMap (Real-Time Demo)
Edit the ConfigMap:
kubectl edit configmap demo-config
Change:
APP_VERSION: "2.0.0"
Save and exit.
Check latest value:
kubectl get configmap demo-config -o yaml
🛑 Important Note:
Pods do NOT automatically pick up ConfigMap changes.
You must restart the Pod.
Delete:
kubectl delete pod configmap-demo-pod
Recreate:
kubectl apply -f pod-configmap-demo.yaml
Exec again:
kubectl exec -it configmap-demo-pod -- sh
echo $VERSION
Now output:
2.0.0
🌟 Thanks for reading! If this post added value, a like ❤️, follow, or share would encourage me to keep creating more content.
— Latchu | Senior DevOps & Cloud Engineer
☁️ AWS | GCP | ☸️ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions





