Kuberneteskubernetesconfigmapsecretsconfigurationproduction-ready
ConfigMaps and Secrets Management
Kubernetes patterns for managing configuration with ConfigMaps, Secrets, environment variables, and volume mounts with auto-reload.
title: "ConfigMaps and Secrets Management" description: "Kubernetes patterns for managing configuration with ConfigMaps, Secrets, environment variables, and volume mounts with auto-reload." category: "Kubernetes" language: "yaml" tags: ["kubernetes", "configmap", "secrets", "configuration", "production-ready"] createdAt: "2025-04-12" updatedAt: "2025-04-28"
Overview
Comprehensive configuration management using ConfigMaps for non-sensitive data and Secrets for credentials, with multiple injection methods (env vars, env files, volume mounts) and automatic reloading on changes.
Code
env:
- name: DB_URL
valueFrom:
secretKeyRef:
name: app-secrets
key: DATABASE_URL
volumeMounts:
- name: config
mountPath: /etc/appNotes
stringDatain Secrets accepts plain text (more readable than base64data)- Volume-mounted ConfigMaps update automatically when the ConfigMap changes (kubelet sync)
- Environment variables from ConfigMaps do NOT update on change (requires pod restart)
- Use Stakater Reloader or config hash annotations to trigger rollouts on config changes
- Never commit Secrets to git; use sealed-secrets, external-secrets-operator, or Vault CSI
optional: falsefails pod startup if the ConfigMap/Secret does not exist