This section explores Kustomize's powerful generators for ConfigMaps and Secrets:
- Creating ConfigMaps from different sources
- Generating Secrets safely
- Understanding when to use each generator type
- From Literals
configMapGenerator:
- name: app-settings
literals:
- DATABASE_URL=localhost:5432
- APP_PORT=8080- From Files
configMapGenerator:
- name: app-config
files:
- config.json
- settings.propertiessecretGenerator:
- name: app-secrets
literals:
- api-key=my-secret-key
- password=very-secret-
Automatic Hashing
- Generates unique names when content changes
- Forces pods to restart when configuration updates
- Ensures configuration changes are applied
-
Multiple Sources
- Literals: Key-value pairs in YAML
- Files: External configuration files
- Env files: Environment variable files
-
Behavior Control
- Replace: Complete replacement
- Merge: Combine with existing values
- Generate the resources:
kubectl kustomize ./- Apply to your cluster:
kubectl apply -k ./-
Secret Management
- Don't commit real secrets to version control
- Use sealed secrets or external secret management
- Consider using environment-specific secrets
-
ConfigMap Organization
- Group related configurations
- Use meaningful names
- Document the purpose of each configuration
-
File Structure
- Keep configuration files close to usage
- Use clear file names
- Maintain proper documentation
- Application configuration
- Environment variables
- API keys and credentials
- Feature flags
- Connection strings