Skip to main content
Now that Kustomize is installed and configured, we’ll start using the tool. The first thing to understand is the kustomization.yaml file — what it is, why Kustomize needs it, and how to configure it. In this example we have a k8s/ directory that contains two Kubernetes manifest files: one for an NGINX Deployment and one for an NGINX Service. When you point Kustomize at the k8s/ folder, it will not automatically process every YAML file there. Instead, Kustomize looks for an explicit file named kustomization.yaml that lists which resources to manage and what transformations to apply.
The file is typically named kustomization.yaml (Kustomize also accepts kustomization.yml or a Kustomization file name depending on version). Kustomize uses this file as the entry point for building resources.
What the kustomization.yaml contains
  • resources: A list of Kubernetes manifest files (relative paths) that Kustomize should include.
  • customizations (transformations): The changes Kustomize will apply to those resources (for example, commonLabels, patchesStrategicMerge, namePrefix, images, etc.).
Common kustomization fields (at-a-glance) Minimal example
In this example commonLabels adds the label company: KodeKloud to every resource produced by the build. This is just one of many transformations Kustomize supports; others include patchesStrategicMerge, namePrefix, images (to change image tags), and more. Build the manifests Point kustomize build at the directory that contains your kustomization.yaml (the k8s/ directory in this example). Kustomize reads the kustomization file, imports the listed resources, applies the configured transformations, and prints the final manifests to stdout:
A slide titled "Kustomize" with bullet points explaining that Kustomize looks for a kustomization file listing the Kubernetes manifests and customizations to apply. It also notes that the kustomize build command combines and transforms manifests but does not apply or deploy them to a cluster.
Deploying the generated manifests Note that kustomize build only prints the transformed manifests; it does not apply them to a cluster. To deploy the generated manifests, pipe the output into kubectl apply -f -:
Ensure your kubectl context is set to the intended cluster/namespace before applying manifests. Piping directly into kubectl apply -f - will make live changes to that cluster.
Additional resources Summary
  • Kustomize requires a kustomization.yaml file as the entry point for builds.
  • The file lists resources to include and the transformations to perform.
  • kustomize build combines manifests, applies transformations, and prints the result to stdout.
  • To deploy the generated manifests, pipe the build output to kubectl apply -f -.

Watch Video