|
| 1 | +# ConfigMaps and Secrets in Kustomize |
| 2 | + |
| 3 | +## What You'll Learn |
| 4 | +This section covers how to manage application configuration using Kustomize: |
| 5 | +- Creating ConfigMaps from files |
| 6 | +- Mounting ConfigMaps in pods |
| 7 | +- Updating configurations for different environments |
| 8 | + |
| 9 | +## Directory Structure |
| 10 | +``` |
| 11 | +. |
| 12 | +├── base/ # Base configuration |
| 13 | +│ ├── config/ # Configuration files |
| 14 | +│ │ └── app.properties # Application properties |
| 15 | +│ ├── deployment.yaml # Deployment using ConfigMap |
| 16 | +│ └── kustomization.yaml # Generates ConfigMap |
| 17 | +└── overlay/ # Environment-specific configs |
| 18 | + ├── config/ |
| 19 | + │ └── app.properties # Modified properties |
| 20 | + └── kustomization.yaml # Updates ConfigMap |
| 21 | +``` |
| 22 | + |
| 23 | +## Understanding the Setup |
| 24 | + |
| 25 | +### Base Configuration |
| 26 | +- `app.properties`: Default application settings |
| 27 | +- `deployment.yaml`: Mounts ConfigMap as a volume |
| 28 | +- `kustomization.yaml`: Generates ConfigMap from properties file |
| 29 | + |
| 30 | +### Overlay Configuration |
| 31 | +- Modified `app.properties` with environment-specific values |
| 32 | +- Uses `replace` behavior to update the entire ConfigMap |
| 33 | + |
| 34 | +## Try It Yourself |
| 35 | + |
| 36 | +1. View the base ConfigMap: |
| 37 | +```bash |
| 38 | +kubectl kustomize base/ |
| 39 | +``` |
| 40 | + |
| 41 | +2. See the modified version: |
| 42 | +```bash |
| 43 | +kubectl kustomize overlay/ |
| 44 | +``` |
| 45 | + |
| 46 | +## Key Features |
| 47 | +1. **ConfigMap Generation** |
| 48 | + - Automatically creates ConfigMaps from files |
| 49 | + - Handles updates and changes |
| 50 | + - Generates unique names when content changes |
| 51 | + |
| 52 | +2. **Volume Mounting** |
| 53 | + - Mounts ConfigMap as a volume |
| 54 | + - Makes configuration available to containers |
| 55 | + - Updates automatically when ConfigMap changes |
| 56 | + |
| 57 | +3. **Environment Overrides** |
| 58 | + - Easy to maintain different configurations |
| 59 | + - No need to duplicate entire files |
| 60 | + - Clear separation of base and environment-specific settings |
| 61 | + |
| 62 | +## Best Practices |
| 63 | +1. Keep sensitive data out of ConfigMaps |
| 64 | +2. Use meaningful file names |
| 65 | +3. Document your configuration structure |
| 66 | +4. Version control your configurations |
0 commit comments