kustomization.yaml files and exploring Kustomize features, the next step is to assemble everything and apply environment-specific changes. Kustomize exists to let you take a shared “base” Kubernetes configuration and customize it per environment (development, staging, production, etc.) without duplicating manifests.
A typical Kustomize project separates reusable manifests (the base) from environment-specific overlays (patches and extras). This approach improves maintainability, reduces duplication, and makes deployments predictable.
Example project layout
Reference the base kustomization from an overlay using a relative path. Older Kustomize versions used the
bases field; the recommended practice is to reference the base via resources: - ../../base so Kustomize includes the base kustomization.- Base: contains shared manifests used by multiple environments (deployments, services, config maps common to all).
- Overlay: references the base using a relative path and applies environment-specific patches or adds resources unique to that environment.
- Overlay file:
k8s/overlays/dev/kustomization.yaml ../../baseresolves by moving fromdev→overlays→k8sand intobase, importing the base kustomization.
db/ and api/) and mirror or reorganize overlays however makes sense for your team. Each kustomization.yaml should import required resources (including sub-kustomizations) and keep environment patches close to the overlay they modify.
Example of a more modular layout:
- Build the manifests for an overlay:
kustomize build overlays/devorkubectl kustomize overlays/dev
- Apply directly with kubectl:
kubectl apply -k overlays/dev
Best practices
- Keep the base minimal and generic — only the common configuration used across environments.
- Place environment-specific settings in overlays, close to the overlay’s
kustomization.yaml. - Prefer
patchesStrategicMergefor simple field overrides likereplicasor container images. UsepatchesJson6902for precise JSON Patch-style changes when needed. - Use relative paths for referencing the base (
resources: - ../../base) to keep overlays portable. - Add new resources in overlays when a component should exist only in specific environments (monitoring, debug tools, etc.).
- Use a
base/directory for shared configuration. - Create an
overlays/directory with one overlay per environment that references the base via a relative path. - Apply environment-specific changes using patches (e.g.,
patchesStrategicMerge). - Overlays can also add new resources that don’t exist in the base.
- Organize directories in the structure that best fits your project—Kustomize is flexible.
If you need JSON Patch-style modifications, you can use
patchesJson6902 instead of patchesStrategicMerge. Strategic merge patches are often simpler for changing fields like replicas.- Kustomize official: https://kustomize.io/
- Kubernetes: https://kubernetes.io/
- kubectl kustomize: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/