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
kubectlusingkubectl apply -k - Installed as a standalone
kustomizeCLI
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:
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:
Verify the binary path:
Warning
Always review scripts before running them in production environments.
Safer approach:
Verify Installation
Check the installed version:
Example output:
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:
Apply manifests:
Preview production manifests:
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:
Apply output to cluster:
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:
Quick Test
Create a simple folder:
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:
Test build:
Or with kubectl:
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, andprod - Avoid storing raw secrets in Git
Do's
- Install standalone Kustomize when you need the latest features
- Use
kubectl apply -kfor simple deployments - Use
kustomize buildto 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:
Move the binary into a directory included in your PATH.
kubectl -k works but kustomize does not
This means Kustomize is available inside kubectl, but the standalone binary is not installed.
Use:
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
kubectlor as a standalone CLI - Standalone Kustomize is useful for CI/CD and newer features
kubectl apply -kapplies Kustomize overlays directly- Always preview generated manifests before applying
- Keep production overlays small, readable, and version-controlled