Kustomize Overlays Guide Kubernetes
Manage Kubernetes manifests with Kustomize overlays. Base and overlay patterns, strategic merge patches, JSON patches, ConfigMap generators.
π‘ Quick Answer: Create a
base/with shared manifests and akustomization.yaml, then createoverlays/dev/andoverlays/prod/that patch the base with environment-specific changes. Apply withkubectl apply -k overlays/prod/.
The Problem
Copy-pasting manifests across environments leads to drift. Helm is powerful but complex for simple customizations. Kustomize is built into kubectl and provides template-free manifest customization through overlays and patches.
The Solution
Directory Structure
app/
βββ base/
β βββ kustomization.yaml
β βββ deployment.yaml
β βββ service.yaml
β βββ configmap.yaml
βββ overlays/
β βββ dev/
β β βββ kustomization.yaml
β β βββ replica-patch.yaml
β βββ prod/
β βββ kustomization.yaml
β βββ replica-patch.yaml
β βββ resources-patch.yamlBase
# base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
commonLabels:
app: my-appProduction Overlay
# overlays/prod/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
namePrefix: prod-
namespace: production
patches:
- path: replica-patch.yaml
- path: resources-patch.yaml
configMapGenerator:
- name: app-config
literals:
- LOG_LEVEL=warn
- ENVIRONMENT=production
images:
- name: my-app
newName: registry.example.com/my-app
newTag: v2.1.0# overlays/prod/replica-patch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 5Apply
# Preview
kubectl kustomize overlays/prod/
# Apply
kubectl apply -k overlays/prod/
# Diff before applying
kubectl diff -k overlays/prod/graph TD
BASE[base/<br/>deployment.yaml<br/>service.yaml] --> DEV[overlays/dev/<br/>replicas: 1<br/>LOG_LEVEL: debug]
BASE --> STAGING[overlays/staging/<br/>replicas: 2<br/>LOG_LEVEL: info]
BASE --> PROD[overlays/prod/<br/>replicas: 5<br/>LOG_LEVEL: warn]Common Issues
βresource not foundβ in overlay
Resource names must match exactly between base and patch. Check metadata.name in both files.
ConfigMapGenerator creates new names on every change
This is intentional β the hash suffix triggers rolling updates. Use generatorOptions: { disableNameSuffixHash: true } to disable (not recommended).
Best Practices
- Base should work standalone β
kubectl apply -k base/should produce a valid deployment - Use
imagestransformer instead of patching image in deployment β cleaner configMapGeneratorfor environment-specific config β automatic hash suffix triggers rolloutskubectl diff -kbefore applying β see exactly what changes- Combine with ArgoCD β point ArgoCD Application at overlay directory
Key Takeaways
- Kustomize is built into kubectl β no extra tools needed
- Base + overlays pattern: shared manifests customized per environment
configMapGeneratorcreates ConfigMaps with content-hash suffixes for automatic rolloutsimagestransformer changes image name/tag without patching the deploymentkubectl diff -kpreviews changes before applying

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses βπ Deepen Your Skills β Hands-on Courses
Courses by CopyPasteLearn.com β Learn IT by Doing
