Skip to main content
This article explains the problem Kustomize solves, why it exists, and how the Kustomize approach (base + overlays) makes environment-specific Kubernetes configuration manageable without duplicating manifests.

The problem: duplicated manifests across environments

Consider a simple NGINX Deployment that defaults to one replica:
Now imagine three environments with different replica requirements:
  • dev: 1 replica (local)
  • stg: 2 replicas
  • prod: 5 replicas
A naive solution is to copy the full Deployment YAML into separate environment folders and change the replicas value in each file. For a small repo this might work, but it quickly becomes unmanageable as the number of resources grows (Services, ConfigMaps, Secrets, etc.). Keeping all copies synchronized is error-prone.
A dark-themed screenshot titled "Why Kustomize" showing a file tree with dev, stg, and prod folders, each containing nginx-depl.yml and service.yml files. The KodeKloud logo appears in the top-right corner.
You would run kubectl against a specific environment directory:
This works but scales poorly.

Kustomize: base + overlays

Kustomize was created to solve exactly this problem: reuse common manifests and apply environment-specific modifications without duplicating entire files. Core concepts
  • Base: the shared, environment-agnostic resources.
  • Overlay: small, environment-specific patches or additions applied on top of the base.
Benefits:
  • No templating language — plain YAML is preserved and remains valid.
  • DRY — put common resources in a base; overlays only modify what changes.
  • Predictable output — Kustomize emits a final manifest you can inspect and apply.

Example: single base, multiple overlays

Base deployment (k8s/base/nginx-depl.yaml):
Base kustomization (k8s/base/kustomization.yaml):
Create small patch files for each environment that only include the fields to change. Staging patch (k8s/overlays/stg/replica-patch.yaml):
Production patch (k8s/overlays/prod/replica-patch.yaml):
Overlay kustomization files reference the base and apply the patch: k8s/overlays/stg/kustomization.yaml:
k8s/overlays/prod/kustomization.yaml:
For dev you can simply reuse the base defaults (no replica patch needed). Repository layout (example)

Workflow and commands

Kustomize composes the final manifest from base + overlay and emits a merged YAML you can apply. Common commands: Example:
kubectl includes a built-in Kustomize implementation. However, it may lag behind the standalone Kustomize project in features. If you need newer Kustomize functionality, install the standalone kustomize binary or ensure your kubectl version supports the desired features.

Quick comparison: base vs overlay

Why choose Kustomize?

  • Keeps YAML readable and valid — no templating syntax injected into manifests.
  • Promotes reuse and reduces duplication by layering environment changes.
  • Produces a final manifest you can inspect, validate, and apply like any other YAML.
Further reading and references:

Watch Video