kustomize
Customize Kubernetes configurations without modifying original YAML
TLDR
Create a kustomization file with resources and namespace
Build a kustomization file and deploy it with kubectl
Set an image in the kustomization file
Search for Kubernetes resources in the current directory to be added to the kustomization file
SYNOPSIS
kustomize <verb> [options]
PARAMETERS
build [directory]
Builds a set of Kubernetes resources from a kustomization.yaml or kustomization.yml file located in the specified directory (defaults to the current directory if omitted). The output is a single YAML stream suitable for applying to a Kubernetes cluster.
create [directory]
Creates a basic kustomization.yaml file in the specified directory. This initializes a new Kustomize project.
edit add|remove|set [options]
Edits the kustomization.yaml file by adding, removing, or setting resources, generators, or other configurations.
--load_restrictor=[LoadRestrictions]
Restricts the ways that files are loaded. Can be 'LoadRestrictionsNone', 'LoadRestrictionsSandbox', or 'LoadRestrictionsRoot'. Defaults to 'LoadRestrictionsSandbox'
-o, --output <path>
Write the output to the file at the provided path. If the flag is not specified, it will write the output to stdout.
--as-files
Instead of a single YAML stream, emit a set of files.
-v, --verbose
Enable verbose logging. Useful for debugging.
-h, --help
Show help message and exit.
--version
Show version information and exit.
DESCRIPTION
Kustomize introduces a template-free way to customize Kubernetes configurations. Instead of using templating tools or complex scripting, kustomize leverages overlays to manage differences between base configurations and variant deployments. It allows you to modify existing Kubernetes resources (e.g., Deployments, Services, ConfigMaps) by adding, patching, or removing fields without altering the original YAML. This declarative approach promotes reproducibility, avoids duplication, and simplifies the process of deploying applications across multiple environments (development, staging, production). It operates entirely on YAML files, providing a native Kubernetes experience without requiring external tools or languages. Kustomize is natively integrated into kubectl, simplifying its adoption and usage within existing Kubernetes workflows. It focuses on managing differences in Kubernetes manifests, which makes it great for handling application configurations on different environments such as Dev, Staging and Prod.
Essentially, kustomize helps to manage, organize, and deploy Kubernetes configurations more efficiently and effectively, especially when dealing with variations in resource definitions across different environments.
CAVEATS
Kustomize primarily manages YAML files. While it integrates with Kubernetes well, it is not a replacement for all configuration management tools. Understanding Kubernetes concepts and resource definitions is crucial for effective Kustomize usage. Changes in Kubernetes API versions might necessitate updates to your kustomization.yaml files.
WORKFLOW
The typical Kustomize workflow involves:
1. Creating a base directory containing the common Kubernetes resource definitions (e.g., Deployments, Services).
2. Creating overlay directories for each environment (e.g., development, staging, production).
3. In each overlay, adding a kustomization.yaml file that specifies the bases (the common resource definitions) and any patches or modifications specific to that environment.
4. Using `kustomize build` to generate the final Kubernetes manifests for each environment.
5. Applying the generated manifests to the corresponding Kubernetes cluster using `kubectl apply -f
KEY CONCEPTS
Bases: Reference to the common Kubernetes resource configurations.
Overlays: Directory containing kustomization.yaml and patch configurations for specific environments.
Patches: YAML files that define modifications to the base resources, such as changing image versions, resource limits, or environment variables.
Generators: Create Kubernetes resources based on a set of declarative specifications. Examples are ConfigMapGenerator and SecretGenerator.
HISTORY
Kustomize was initially developed as a standalone tool to address the challenges of managing Kubernetes configurations without templating. It gained significant popularity within the Kubernetes community due to its simplicity and declarative approach. Subsequently, kustomize was integrated into kubectl (starting with Kubernetes version 1.14), making it a core component of Kubernetes configuration management. The tool continues to evolve with new features and improvements driven by community contributions and the Kubernetes roadmap.