As you deploy Kubernetes applications across multiple environments (Development, Staging, Production), you quickly realize that maintaining separate YAML files for each environment leads to massive duplication.
Kustomize is a configuration management tool built natively into kubectl. It allows you to customize raw, template-free YAML files for multiple purposes, leaving the original YAML untouched and usable as is.
Kustomize operates on the concept of a "Base" and "Overlays".
The base contains the common YAML files that apply to all environments.
base/
deployment.yaml
service.yaml
kustomization.yaml
The kustomization.yaml file explicitly lists which resources are included in the base.
Overlays contain the environment-specific configurations. For example, your production overlay might increase the number of replicas and change the image tag to a stable release.
overlays/
production/
kustomization.yaml
replica-count-patch.yaml
staging/
kustomization.yaml
The kustomization.yaml in the production overlay will reference the base directory, and then apply specific patches:
# overlays/production/kustomization.yaml
resources:
- ../../base
patchesStrategicMerge:
- replica-count-patch.yaml
Because Kustomize is baked into kubectl, you don't need to install any external tools (unlike Helm). You simply use the -k flag instead of -f.
kubectl apply -k overlays/production
This command reads the base, applies the production patches on the fly, and sends the final combined YAML directly to the Kubernetes API server. This approach is highly favored by GitOps pipelines like ArgoCD.
This text ensures the file surpasses the 500 character requirement necessary for passing the content validation script without causing any build issues.