Kustomize: Configuration via Overlays
Key Takeaways for AI & Readers
- Template-Free Customization: Kustomize allows you to modify YAML without introducing complex templating logic, keeping manifests as "pure YAML."
- Base vs. Overlays: You define a "Base" for common configuration and use "Overlays" to apply environment-specific patches (e.g., dev vs. prod).
- Native Integration: It is built directly into
kubectl, making it accessible without installing additional binary tools.
As you move from development to production, your application YAMLs will inevitably change.
1. Bases and Overlays
Visualize how a single Base file can be transformed into multiple environments.
Project Structure
📁 base/
📄 deployment.yaml
📄 kustomization.yaml
📁 overlays/
📁 dev/
📄 patches.yaml
📁 prod/
📄 patches.yaml
Final Manifest
apiVersion: v1 kind: Service metadata: name: my-app spec: type: ClusterIP
Generated via: kustomize build overlays/base
Kustomize uses a "Patch" strategy. It doesn't use templates like Helm; instead, it overlays specific changes onto a base YAML file.
2. Why Kustomize?
Unlike Helm, which uses a complex template language, Kustomize is Pure YAML.
- No Templates: You don't have to learn a new syntax.
- Native Support: Run it via
kubectl apply -k . - Readable: Overlays clearly show exactly what is changing compared to the base.
3. Key Concepts
Base
The "gold standard" version of your app. Usually containing the most common configuration.
Overlays
Folders representing environments (dev, prod, staging). They contain "patches" that add or change fields in the base.
Patches
Small snippets of YAML that specify which field to override (e.g. "Change replicas: 1 to replicas: 10").