Skip to content

11.03 Kustomize Installation

Abstract

Kustomize is a Kubernetes configuration management tool used to customize manifests without templates.

It can be used in two ways:

  • Built into kubectl using kubectl apply -k
  • Installed as a standalone kustomize CLI

Prerequisites

Before installing Kustomize, make sure you have:

Requirement Purpose
Kubernetes cluster Target cluster where manifests will be applied
kubectl Kubernetes CLI tool
Valid kubeconfig Allows access to the correct cluster
Terminal access Required to install and verify Kustomize

Check cluster access:

kubectl cluster-info
kubectl get nodes

Note

Kustomize is useful only when your kubectl is already configured to communicate with the intended Kubernetes cluster.


Installation Options

Kustomize can be installed on:

  • Linux
  • macOS
  • Windows

The Kustomize project provides an installation script that detects the operating system and downloads the correct binary.

Tip

kubectl already includes Kustomize support, but the standalone CLI may provide newer features depending on your installed kubectl version.


Install Kustomize

Run the official install script:

curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash

This downloads the kustomize binary into the current directory.

Move it into your system path:

sudo mv kustomize /usr/local/bin/

Verify the binary path:

which kustomize

Warning

Always review scripts before running them in production environments.

Safer approach:

curl -s -O https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh
cat install_kustomize.sh
bash install_kustomize.sh

Verify Installation

Check the installed version:

kustomize version --short

Example output:

{kustomize/v4.4.1  2021-11-11T23:36:27Z  }

If this command returns a version, Kustomize is installed successfully.

Success

Kustomize installation is complete when the kustomize command is available in your terminal.


Using Kustomize with kubectl

Even without the standalone binary, you can use Kustomize through kubectl.

Build manifests:

kubectl kustomize overlays/dev

Apply manifests:

kubectl apply -k overlays/dev

Preview production manifests:

kubectl kustomize overlays/prod

Note

The standalone kustomize CLI and kubectl -k may not always be the same version.


Standalone CLI vs kubectl Built-in

Option Command Use Case
Built into kubectl kubectl apply -k overlays/prod Simple apply workflow
Standalone CLI kustomize build overlays/prod Build, test, debug, CI/CD validation

Example standalone build:

kustomize build overlays/prod

Apply output to cluster:

kustomize build overlays/prod | kubectl apply -f -

Tip

In CI/CD pipelines, render manifests first, validate them, then apply.


Basic Folder Structure

A common Kustomize project structure:

k8s/
├── base/
│   ├── kustomization.yaml
│   ├── deployment.yaml
│   └── service.yaml
└── overlays/
    ├── dev/
    │   └── kustomization.yaml
    ├── stg/
    │   └── kustomization.yaml
    └── prod/
        └── kustomization.yaml

Apply a specific environment:

kubectl apply -k k8s/overlays/prod

Quick Test

Create a simple folder:

mkdir -p k8s/base

Create deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx

Create kustomization.yaml:

resources:
  - deployment.yaml

Test build:

kustomize build k8s/base

Or with kubectl:

kubectl kustomize k8s/base

Production Best Practices

Recommended

  • Keep Kustomize manifests in Git
  • Use base/ for shared resources
  • Use overlays/ for environment-specific changes
  • Validate rendered YAML before applying
  • Use CI/CD to run kustomize build
  • Keep overlays small and readable
  • Use separate overlays for dev, stg, and prod
  • Avoid storing raw secrets in Git

Do's

  • Install standalone Kustomize when you need the latest features
  • Use kubectl apply -k for simple deployments
  • Use kustomize build to preview final manifests
  • Check versions before debugging build differences
  • Store base and overlay files clearly

Don'ts

  • Don't blindly run installation scripts in production systems
  • Don't keep environment-specific settings in the base
  • Don't duplicate full YAML files for each environment
  • Don't store passwords or tokens in plain YAML
  • Don't apply manifests without previewing them

Troubleshooting

Command not found

If kustomize is not found:

echo $PATH
ls -l /usr/local/bin/kustomize

Move the binary into a directory included in your PATH.

Version does not show

Close and reopen the terminal session.

Then run:

kustomize version --short

kubectl -k works but kustomize does not

This means Kustomize is available inside kubectl, but the standalone binary is not installed.

Use:

kubectl apply -k overlays/dev

Useful Commands

Task Command
Check Kustomize version kustomize version --short
Build manifests kustomize build overlays/prod
Apply with kubectl kubectl apply -k overlays/prod
Preview with kubectl kubectl kustomize overlays/prod
Validate cluster access kubectl get nodes

Summary

Quote

  • Kustomize can be used through kubectl or as a standalone CLI
  • Standalone Kustomize is useful for CI/CD and newer features
  • kubectl apply -k applies Kustomize overlays directly
  • Always preview generated manifests before applying
  • Keep production overlays small, readable, and version-controlled