Kustomize: Template-Free Kubernetes Configs
Kustomize manages environment-specific Kubernetes configs by layering patches on a base YAML, avoiding complex templating. Use it to tweak deployments for dev, staging, or prod. The footgun: the `kubectl` version can lag, causing unexpected behavior.
WHY IT EXISTS Managing Kubernetes configurations across different environments like development, staging, and production is a common challenge. Simply copying and pasting YAML files leads to maintenance nightmares. Full-blown templating engines can introduce their own complexity. Kustomize was created to solve this by enabling declarative, template-free customization of YAML files.
THE MENTAL MODEL Think of Kustomize as a patch-and-layer system for your configs. You have a common 'base' set of YAML files, and for each environment, you define an 'overlay' that applies specific modifications. It's like the build tool 'make' because its actions are declared in a file, and it's like the text editor 'sed' because it emits modified text, but it understands the structure of Kubernetes objects.
HOW IT WORKS You define your customizations in a file named kustomization.yaml. This file specifies a set of base resources and a list of patches to apply. Patches can do things like add common labels, change image tags, or modify resource limits. When you run kustomize build, it reads the base files, applies the patches in memory, and outputs a single, final YAML manifest to standard output. The original files are never modified.
WHEN TO USE IT Use Kustomize when you need to manage slight variations of a core application configuration across multiple environments. It excels at tasks like adjusting replica counts, injecting environment-specific ConfigMaps, or adding sidecar containers for production but not development. Since it's built directly into kubectl (using kubectl apply -k .), it integrates seamlessly into existing CI/CD workflows.
WHEN NOT TO USE IT Kustomize is not a package manager. If you need to manage complex applications with dependencies, versioning, and release lifecycle hooks (install, upgrade, rollback), a tool like Helm is more suitable. Kustomize focuses purely on the generation and customization of Kubernetes YAML manifests.
ONE CANONICAL EXAMPLE A common pattern is to have a base directory with your core deployment.yaml and service.yaml. You then create an overlays/production directory containing a kustomization.yaml file. This overlay file references the base and specifies a patch to increase the replica count from 1 to 10 and update the container image to a specific production tag. Running kustomize build overlays/production generates the final production-ready manifest.
Read the original → github.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.