🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Articles

What is Kustomize? Kubernetes Config Management Explained Simply

Kustomize lets you customize Kubernetes YAML without copying and editing files. Here's what it is, how it works, and when to use it instead of Helm.

DevOpsBoysMay 10, 20263 min read
Share:Tweet

You have the same Kubernetes app running in dev, staging, and prod. The only differences are: the image tag, the replica count, and a few environment variables.

Do you copy the YAML three times and edit each one? No. You use Kustomize.


What is Kustomize?

Kustomize is a tool built into kubectl that lets you customize Kubernetes YAML files without modifying the original. You define a base configuration and then apply overlays per environment.

No templates. No new syntax. Just plain Kubernetes YAML plus a kustomization.yaml file.

bash
# Already built into kubectl
kubectl apply -k ./overlays/prod/
 
# Or use the standalone binary
kustomize build ./overlays/prod/ | kubectl apply -f -

The Problem Kustomize Solves

Imagine this structure without Kustomize:

k8s/
  dev/
    deployment.yaml      # replicas: 1, image: myapp:dev
    service.yaml
    configmap.yaml
  prod/
    deployment.yaml      # replicas: 5, image: myapp:v1.2.3
    service.yaml
    configmap.yaml

Six files. Most of them are 90% identical. When you change the Service port, you change it in two places. When you add a label, you add it in two places.

Kustomize fixes this.


How Kustomize Works

Base + Overlay Model

k8s/
  base/
    deployment.yaml       # shared config
    service.yaml
    kustomization.yaml    # lists what's in base
  overlays/
    dev/
      kustomization.yaml  # patches for dev
    prod/
      kustomization.yaml  # patches for prod
      replica-patch.yaml  # specific prod changes

The Base

k8s/base/deployment.yaml:

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: myapp:latest
          ports:
            - containerPort: 8080

k8s/base/kustomization.yaml:

yaml
resources:
  - deployment.yaml
  - service.yaml

The Prod Overlay

k8s/overlays/prod/kustomization.yaml:

yaml
bases:
  - ../../base
 
images:
  - name: myapp
    newTag: v1.2.3       # override the image tag
 
patches:
  - path: replica-patch.yaml
 
commonLabels:
  environment: production

k8s/overlays/prod/replica-patch.yaml:

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 5             # override replicas for prod

Deploy to Prod

bash
kubectl apply -k k8s/overlays/prod/

Kustomize merges the base + overlay and applies the result. The base files are never modified.


Common Kustomize Features

1. Image Tag Override

yaml
# kustomization.yaml
images:
  - name: myapp
    newTag: "$(IMAGE_TAG)"    # works with CI/CD variables
bash
# In your CI pipeline:
kustomize edit set image myapp:$CI_COMMIT_SHA
kubectl apply -k .

2. ConfigMap Generator

Instead of writing a ConfigMap YAML, generate it from a file:

yaml
# kustomization.yaml
configMapGenerator:
  - name: app-config
    files:
      - config/app.properties
    literals:
      - APP_ENV=production
      - LOG_LEVEL=info

Kustomize auto-appends a hash to the name (app-config-abc123) so pods restart automatically when config changes.

3. Namespace Override

yaml
# kustomization.yaml
namespace: production    # applies to all resources

4. Common Labels and Annotations

yaml
# kustomization.yaml
commonLabels:
  team: backend
  app: myapp
 
commonAnnotations:
  managed-by: kustomize

5. Strategic Merge Patch vs JSON Patch

Strategic Merge Patch (easiest — just write partial YAML):

yaml
# replica-patch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 5

JSON 6902 Patch (more precise):

yaml
# kustomization.yaml
patches:
  - target:
      kind: Deployment
      name: myapp
    patch: |-
      - op: replace
        path: /spec/replicas
        value: 5

Kustomize vs Helm

KustomizeHelm
SyntaxPlain YAMLGo templates
Learning curveLowMedium
Package managementNoYes (charts)
Versioning/rollbackVia GitBuilt-in
Community chartsNoThousands
GitOps (ArgoCD/Flux)Native supportSupported

Use Kustomize when:

  • You own the app and manage the YAML
  • You want simple environment-specific overrides
  • You're using GitOps with ArgoCD or Flux

Use Helm when:

  • You're installing third-party software (Prometheus, Nginx, etc.)
  • You need parameterized charts shared across teams
  • You want versioned releases with rollback

Many teams use both: Helm to install third-party tools, Kustomize to manage their own apps.


With ArgoCD

ArgoCD has native Kustomize support:

yaml
# ArgoCD Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp-prod
spec:
  source:
    repoURL: https://github.com/myorg/k8s-configs
    targetRevision: main
    path: overlays/prod      # ArgoCD runs kustomize build here
  destination:
    server: https://kubernetes.default.svc
    namespace: production

When you push a new image tag to the overlay, ArgoCD detects the change and syncs automatically.


Quick Start in 5 Minutes

bash
# Install kustomize
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
 
# Preview what will be applied (dry run)
kustomize build overlays/prod/
 
# Apply
kubectl apply -k overlays/prod/
 
# Diff against live cluster
kubectl diff -k overlays/prod/

Kustomize is one of those tools that feels unnecessary until you have 3+ environments, then it becomes essential. Start with the base + overlay pattern and you'll never go back to copy-pasting YAML.

For a full Kubernetes configuration management course including Kustomize and Helm labs, check out KodeKloud.

Newsletter

Stay ahead of the curve

Get the latest DevOps, Kubernetes, AWS, and AI/ML guides delivered straight to your inbox. No spam — just practical engineering content.

Related Articles

Comments