Use ConfigMaps¶
Problem¶
Applications often require configuration such as:
- API endpoints
- feature flags
- application settings
Hardcoding these values inside container images makes them difficult to change.
Kubernetes ConfigMaps allow configuration to be injected into pods.
Step 1 — Create a ConfigMap¶
Create configmap.yaml.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_ENV: production
API_URL: https://api.example.com
Apply it.
Verify.
Expected output:
Step 2 — Use ConfigMap in Deployment¶
Update the deployment.
deployment.yaml
Full container example:
Apply.
Step 3 — Verify Environment Variables¶
Enter the pod.
Check variables.
Expected:
Troubleshooting¶
ConfigMap Not Found
Check:
Pod Not Restarting
ConfigMap updates do not restart pods automatically.
Restart deployment.