Kustomize

Difficulty: Intermediate

Question

What is Kustomize, and how does it let you manage per-environment Kubernetes manifests without templates?

Answer

Kustomize is a template-free configuration tool for Kubernetes that builds final manifests by layering patches and transformations on top of plain YAML. You keep a shared base and add small overlays for each environment, and it is built into kubectl, so kubectl apply -k overlays/prod renders and applies everything in one step.

Bases, overlays and kustomization.yaml

Every Kustomize directory has a kustomization.yaml that lists what to include and what to change:

  • resources: the YAML files or other kustomization directories to start from
  • patches: strategic merge patches or JSON 6902 patches that change specific fields
  • images: swap image names or tags without touching the Deployment
  • namePrefix / nameSuffix and namespace: rename or move every resource
  • labels: add labels (and optionally selectors) everywhere
  • configMapGenerator / secretGenerator: create ConfigMaps and Secrets from files or literals

A typical layout is base/ with the Deployment and Service, then overlays/dev, overlays/staging and overlays/prod, each referencing ../../base and changing only what differs, such as replicas, resources and the image tag.

Why "no templates" matters

The base files are valid Kubernetes YAML that you can kubectl apply directly. There are no {{ }} placeholders, so linters, IDE schemas and code review all work on real manifests. Kustomize understands Kubernetes object structure, which means a patch only needs the identifying fields (apiVersion, kind, metadata.name) plus the fields you want to change.

Kustomize vs Helm

AspectKustomizeHelm
ApproachPatch plain YAMLRender Go templates
Built into kubectlYes (-k)No, separate CLI
Packaging and versioningNone, just directoriesVersioned charts in repos/OCI
Release tracking and rollbackNoYes, stored revisions
Best forYour own apps across environmentsDistributing reusable apps

Many teams combine them: install third-party software with Helm and manage in-house services with Kustomize, or use Kustomize's helmCharts field (with --enable-helm) to patch a chart's output.

Gotchas worth knowing

  • configMapGenerator appends a content hash to the name (for example app-config-7f8k2m). When the config changes, the name changes, the Deployment reference updates, and Pods roll out automatically. This is a feature, but surprises people who hard-code the name.
  • The Kustomize version embedded in kubectl lags the standalone kustomize binary, so newer fields may only work with the standalone tool.
  • Older fields like patchesStrategicMerge, patchesJson6902 and commonLabels are deprecated in favour of patches and labels; kustomize edit fix migrates them.
  • Kustomize has no idea what is already in the cluster, so it cannot prune or roll back on its own. GitOps tools such as Argo CD and Flux, which both support Kustomize natively, fill that gap.
How a Kustomize overlay is built. Each layer adds changes on top of the plain YAML below it.
  1. Final rendered manifests: What kubectl apply -k sends to the cluster.
  2. overlays/prod: Replicas, resources and image tag for production.
  3. Generators and transformers: ConfigMaps with hash suffixes, labels, namespace.
  4. base: Plain Deployment and Service YAML shared by all environments.

Code examples

Base and production overlay

# base/kustomization.yaml
resources:
  - deployment.yaml
  - service.yaml

# overlays/prod/kustomization.yaml
resources:
  - ../../base
namespace: shop-prod
images:
  - name: ghcr.io/acme/checkout
    newTag: "1.5.0"
patches:
  - target:
      kind: Deployment
      name: checkout
    patch: |-
      - op: replace
        path: /spec/replicas
        value: 6
configMapGenerator:
  - name: checkout-config
    literals:
      - PAYMENT_TIMEOUT_MS=3000

The prod overlay reuses the base unchanged and only declares the differences: namespace, image tag, replica count and config.

Render, diff and apply

# See the final YAML without applying
kubectl kustomize overlays/prod

# Compare with what is running
kubectl diff -k overlays/prod

# Apply
kubectl apply -k overlays/prod

Rendering and diffing before applying is the standard review loop for Kustomize changes.

Key points

  • Kustomize patches plain YAML instead of templating it
  • Built into kubectl since 1.14 via kubectl apply -k and kubectl kustomize
  • Base holds shared manifests; overlays hold per-environment differences
  • configMapGenerator adds a hash suffix so config changes trigger a rollout
  • No release tracking or rollback; pair it with GitOps for that

Common follow-up questions

  • When would you choose Helm over Kustomize?
  • What is the difference between a strategic merge patch and a JSON 6902 patch?
  • Why does configMapGenerator add a hash suffix to the name?
  • How do you use Kustomize with Argo CD?

Interview tips

  • Lead with 'template-free, patch-based', which is the key difference from Helm
  • Sketch the base/overlays folder structure; it makes the answer concrete
  • Mention the configMapGenerator hash trick, interviewers like it

Concepts covered

Kustomize, Bases and Overlays, Patches, configMapGenerator, kubectl apply -k

More Kubernetes & Orchestration questions