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.
The application demonstrates how configuration and secrets flow into containers in Kubernetes.
User ⬇ Kubernetes Cluster ⬇ Deployment (3 Pods) ⬇ ConfigMap + Secret ⬇ Application Containers
- Kubernetes
- ConfigMap
- Secret
- Deployment
- BusyBox (test container)
- kubectl CLI
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
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
Apply:
kubectl apply -f 02-configmap-as-envvars.yaml
Verify:
kubectl logs env-pod
Apply:
kubectl apply -f 03-configmap-selective-env.yaml
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
kubectl apply -f 06-secret-as-envvars.yaml
Verify:
kubectl logs db-pod
kubectl apply -f 08-combined-cm-and-secret.yaml
Verify environment variables:
kubectl exec -it fullapp-pod -- env
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
| Feature | ConfigMap | Secret |
|---|---|---|
| Purpose | Non-sensitive configuration | Sensitive data |
| Examples | Ports, environment names | Passwords, API keys |
| Encoding | Plain text | Base64 encoded |
- 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
Ahmed Sabra DevOps Trainee — Digilians DevOps Intensive Program
Give the repository a Star ⭐ on GitHub.
