Hardcoding configuration into container images is a common beginner mistake. Database hostnames, API keys, feature flags — none of this belongs in your Docker image. Kubernetes provides ConfigMaps for non-sensitive data and Secrets for sensitive data.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
DB_HOST: "postgres-service"
DB_PORT: "5432"
LOG_LEVEL: "info"
kubectl create secret generic db-credentials \
--from-literal=username=admin \
--from-literal=password=s3cur3-pass
Never commit secrets to Git. Never log them. Never print them in error messages. The number of production breaches caused by leaked credentials is staggering.
In Part 6, we cover persistent storage for databases and stateful applications.
← Back to Blog