Kustomize
Manage multi-environment deployments using Kustomize overlays.
Time: ~10 minutes Difficulty: Intermediate
What You Will Learn
Section titled “What You Will Learn”- Base + overlay pattern for DRY configuration
- Environment-specific patches (replicas, resources, env vars)
- Kustomize name prefixes and namespace scoping
- ConfigMap generation from files
Deploy
Section titled “Deploy”Navigate to the demo directory:
cd demos/kustomizeDeploy the development overlay:
kubectl apply -k overlays/development/Deploy the production overlay:
kubectl apply -k overlays/production/Verify
Section titled “Verify”# Developmentkubectl get pods -n kustomize-devkubectl port-forward svc/dev-nginx-service 8081:80 -n kustomize-dev
# Productionkubectl get pods -n kustomize-prodkubectl port-forward svc/prod-nginx-service 8082:80 -n kustomize-prodOpen http://localhost:8081 for the dev page (orange) and http://localhost:8082 for the prod page (green).
What is Happening
Section titled “What is Happening”base/ # Shared configuration deployment.yaml # 3 replicas, health checks, resource limits service.yaml # ClusterIP on port 80 configmap.yaml # nginx config + landing page kustomization.yaml # Ties it together
overlays/ development/ # Dev-specific overrides kustomization.yaml # 2 replicas, dev- prefix, lower resources deployment-patch.yaml # Smaller CPU/memory limits ingress.yaml # nginx-dev.local hostname index.html # Orange-themed landing page
production/ # Prod-specific overrides kustomization.yaml # 5 replicas, prod- prefix, higher resources deployment-patch.yaml # Larger CPU/memory limits ingress.yaml # nginx-prod.local hostname index.html # Green-themed landing pageBoth environments share the same base manifests. Overlays only specify what differs: replica count, resource limits, namespace, and visual theme.
Experiment
Section titled “Experiment”-
Preview what Kustomize generates without applying:
Terminal window kubectl kustomize overlays/development/ -
Compare the two environments:
Terminal window diff <(kubectl kustomize overlays/development/) \<(kubectl kustomize overlays/production/) -
Add a new environment (e.g., staging) by creating a new overlay directory:
Terminal window cp -r overlays/development/ overlays/staging/Then edit
kustomization.yamlto set a different namespace, prefix, and replica count.
Cleanup
Section titled “Cleanup”kubectl delete namespace kustomize-dev kustomize-prodFurther Reading
Section titled “Further Reading”See docs/deep-dive.md for a detailed explanation of the base+overlay model, configMapGenerator internals, strategic merge patches vs JSON patches, and how to build a staging overlay from scratch.
Next Step
Section titled “Next Step”Move on to ArgoCD to automate deployments with GitOps.