Store config in env vars (Twelve-Factor); K8s ConfigMaps for config, Secrets for credentials.
Configuration Management
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
database_url: str
redis_url: str = "redis://localhost:6379"
jwt_secret: str
log_level: str = "INFO"
class Config:
env_file = ".env"
settings = Settings()
# .env (local dev, never commit!)
DATABASE_URL=postgresql://user:pass@localhost/users
JWT_SECRET=dev-secret
# K8s ConfigMap (non-sensitive)
kubectl create configmap svc-config
--from-literal=LOG_LEVEL=INFO
# K8s Secret (sensitive)
kubectl create secret generic svc-secrets
--from-literal=DATABASE_URL=postgresql://...
--from-literal=JWT_SECRET=prod-secret