Skip to content

AhmedSabra-DevOps/ConfigMap-Lab

Repository files navigation

🚀 Kubernetes ConfigMap & Secret Lab

Hands-on Kubernetes lab focused on ConfigMap, Secret, and Deployment configuration management.

This project demonstrates how to manage application configuration and sensitive data in Kubernetes using best practices.


🏗️ Architecture Diagram

Architecture Overview

The application demonstrates how configuration and secrets flow into containers in Kubernetes.

User ⬇ Kubernetes Cluster ⬇ Deployment (3 Pods) ⬇ ConfigMap + Secret ⬇ Application Containers


📦 Technologies Used

  • Kubernetes
  • ConfigMap
  • Secret
  • Deployment
  • BusyBox (test container)
  • kubectl CLI

📂 Project Structure

k8s-configmap-secret-lab
│
├── 02-configmap-as-envvars.yaml
├── 03-configmap-selective-env.yaml
├── 06-secret-as-envvars.yaml
├── 08-combined-cm-and-secret.yaml
├── 09-deployment-with-config.yaml
│
├── docs
│   └── architecture.png
│
└── README.md

⚙️ Lab Tasks

1️⃣ Create ConfigMap

Create configuration values for the application.

Example:

APP_ENV=production
APP_PORT=8080
APP_COLOR=blue
MAX_CONNECTIONS=100

Command:

kubectl create configmap app-config \
--from-literal=APP_ENV=production \
--from-literal=APP_PORT=8080 \
--from-literal=APP_COLOR=blue \
--from-literal=MAX_CONNECTIONS=100

2️⃣ Inject ConfigMap into Pod

Apply:

kubectl apply -f 02-configmap-as-envvars.yaml

Verify:

kubectl logs env-pod

3️⃣ Inject Specific ConfigMap Keys

Apply:

kubectl apply -f 03-configmap-selective-env.yaml

4️⃣ Create Kubernetes Secret

kubectl create secret generic db-secret \
--from-literal=DB_USER=admin \
--from-literal=DB_PASSWORD=p@ssw0rd123 \
--from-literal=DB_NAME=myapp

Verify:

kubectl get secret

5️⃣ Inject Secret into Pod

kubectl apply -f 06-secret-as-envvars.yaml

Verify:

kubectl logs db-pod

6️⃣ Combine ConfigMap + Secret

kubectl apply -f 08-combined-cm-and-secret.yaml

Verify environment variables:

kubectl exec -it fullapp-pod -- env

7️⃣ Deployment with ConfigMap + Secret

Create deployment with 3 replicas:

kubectl apply -f 09-deployment-with-config.yaml

Verify pods:

kubectl get pods

Check environment variables:

kubectl exec -it <pod-name> -- env

🔐 ConfigMap vs Secret

Feature ConfigMap Secret
Purpose Non-sensitive configuration Sensitive data
Examples Ports, environment names Passwords, API keys
Encoding Plain text Base64 encoded

🧠 Key Learning Points

  • How to externalize configuration in Kubernetes
  • Securely manage sensitive information
  • Inject configuration into containers
  • Use ConfigMap and Secret with Deployments
  • Maintain consistent configuration across multiple pods

📚 Author

Ahmed Sabra DevOps Trainee — Digilians DevOps Intensive Program


⭐ If you like this project

Give the repository a Star ⭐ on GitHub.

ConfigMap-Lab

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors