How to Use Kustomize for Kubernetes Configuration Management

Kustomize provides template-free customization of Kubernetes manifests — managing environment-specific variations (dev, staging, production) without duplicating entire YAML files. This guide covers the core workflow.

The Problem Kustomize Solves

Different environments typically need slightly different configuration (replica counts, resource limits, environment variables) from a common base — without a tool like Kustomize, teams often resort to duplicating entire manifest files with small variations, or complex templating that can be hard to reason about.

Kustomize's Approach: Base + Overlays

base/
  deployment.yaml
  service.yaml
  kustomization.yaml
overlays/
  production/
    kustomization.yaml
    replica-patch.yaml
  staging/
    kustomization.yaml

A base configuration defines common resources; overlays apply environment-specific patches on top — no templating language, just structured patches to plain Kubernetes YAML.

Basic kustomization.yaml (Base)

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml
  - service.yaml

Production Overlay with a Replica Patch

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base
patches:
  - path: replica-patch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 5

Production overrides the base's replica count (perhaps 1 or 2 in base/dev) to a production-appropriate 5, without duplicating the entire deployment definition.

Building and Applying with Kustomize

kubectl apply -k overlays/production

kubectl has built-in Kustomize support (-k flag) — no separate tool installation needed for basic usage.

Previewing Generated Output Before Applying

kubectl kustomize overlays/production

Shows the fully-resolved manifest (base plus overlay patches applied) without actually applying it — useful for reviewing exactly what will be deployed before committing to the change.

Setting Environment-Specific ConfigMap Values

configMapGenerator:
  - name: app-config
    literals:
      - API_URL=https://staging-api.yourdomain.com

Kustomize can generate ConfigMaps with environment-specific values directly, integrated into the overlay pattern rather than needing separate manual ConfigMap definitions per environment.

Adding Environment-Specific Labels

commonLabels:
  environment: production

Automatically applies consistent labeling across all resources in an overlay, useful for filtering/organizing resources by environment.

Combining with GitOps (ArgoCD)

See How to Set Up a Kubernetes CI/CD Pipeline with ArgoCD (GitOps) — ArgoCD has native Kustomize support, letting you point an ArgoCD Application directly at a Kustomize overlay path, combining both tools naturally.

Kustomize vs Helm

See How to Install and Use Helm: The Kubernetes Package Manager for comparison — Helm uses templating with a packaging/versioning model (charts); Kustomize uses patch-based customization of plain YAML without templating syntax; both are valid approaches, sometimes used together (Kustomize patching Helm-rendered output).

Common Errors

Patch doesn't seem to apply correctly — verify the patch's resource name/kind exactly matches the base resource it's meant to modify; Kustomize matches patches to base resources by name and kind, and a mismatch silently fails to apply as expected.

Continue Reading

Browse more articles in Kubernetes & Container Orchestration.

  • kustomize kubernetes tutorial, kubernetes base overlay pattern, kustomize vs helm, kubectl apply -k
  • 0 Korisnici koji smatraju članak korisnim
Je li Vam ovaj odgovor pomogao?

Vezani članci

What Is Kubernetes and When Do You Need It on a VPS?

Kubernetes is a container orchestration platform — it automates deploying, scaling, and...

How to Install a Single-Node Kubernetes Cluster with k3s

k3s is a lightweight, certified Kubernetes distribution designed to run efficiently on modest...

How to Install kubeadm and Set Up a Multi-Node Kubernetes Cluster

kubeadm is the official tool for bootstrapping a standard, full-featured Kubernetes cluster. This...

Kubernetes Pods, Deployments & Services Explained

Understanding these three core Kubernetes objects — Pods, Deployments, and Services —...

How to Expose Applications with a Kubernetes Ingress Controller (Nginx Ingress)

An Ingress lets you route external HTTP/HTTPS traffic to multiple services within your cluster...