Skip to main content
Now that Kustomize is installed and configured, this lesson explains the kustomization.yaml file: what it is, why it’s required, and how to configure it for common use cases. In this example repository we have a k8s/ directory containing two Kubernetes manifests:
  • nginx-deployment.yaml
  • nginx-service.yaml
Kustomize does not automatically process every YAML in a folder. Instead, it looks for a single, specific file named kustomization.yaml (some Kustomize versions accept kustomization.yml or Kustomization). Create this file in the directory you want Kustomize to manage.
The kustomization.yaml file tells Kustomize which resources to include and which transformations (labels, patches, image overrides, etc.) to apply. Without it, Kustomize has no entry point.
kustomization.yaml has two primary responsibilities:
  1. Declare the Kubernetes resources (manifests) Kustomize should manage.
  2. Define the customizations (transformations) to apply to those resources.
Minimal example Below is a minimal kustomization.yaml that includes the two manifests and applies a common label across all resources:
How this works
  • The resources list enumerates each manifest file that Kustomize will read and include in the build.
  • The commonLabels entry instructs Kustomize to add company: KodeKloud to every resource included in the generated output.
What else can you put in kustomization.yaml? Kustomize supports many transformations. Here are common fields you will see in kustomization files: Note: When including examples with braces or other special characters in tables or inline examples, wrap them in backticks (e.g., [{ "object": "person" }]) so MDX parsers don’t interpret them. Running Kustomize To build the final manifest YAML from a kustomization directory, run:
What happens when you run this command:
  • Kustomize reads k8s/kustomization.yaml.
  • It imports the files listed in resources.
  • It applies the transformations declared in the kustomization file.
  • It prints the final YAML to stdout.
Important: kustomize build generates the manifests but does not apply them to a Kubernetes cluster. To apply the generated manifests, pipe the output into kubectl:
Or let kubectl perform the kustomize build and apply in one step:
This uses your current kubeconfig context to create or update resources in the cluster. Example build output After running kustomize build k8s, the output will include both the Service and the Deployment manifests with the added label. For example:
Best practices and tips
  • Keep your kustomization.yaml focused: list only the resources you intend to manage in that kustomization directory.
  • Use namePrefix or nameSuffix to avoid naming collisions across environments.
  • Prefer patchesStrategicMerge or JSON patches for environment-specific modifications rather than maintaining duplicate manifests.
  • For complex setups, break overlays into separate directories (base + overlays) and reference them via resources or bases.
References and further reading Summary
  • Kustomize looks for kustomization.yaml in the directory you point it to.
  • That file declares (a) the list of resource manifests to include and (b) the customizations/transformations to apply.
  • Use kustomize build <dir> to produce the final YAML and pipe it to kubectl apply -f - or use kubectl apply -k <dir> to apply directly.

Watch Video