kustomize build produces and how to apply those manifests to your Kubernetes cluster.
What kustomize build does
- Collects every resource referenced by a
kustomization.yaml(bases, resources, patches, etc.). - Applies configured transformations (patches,
namePrefix,namespace, image tags, commonLabels, etc.). - Writes the fully rendered YAML manifests to stdout (the console).
kustomize build only generates the final manifests — it does not create, modify, or delete any resources in your cluster. If you run kustomize build and then check the cluster with kubectl get pods (or kubectl get deployments, kubectl get services), you will see no changes until you apply those manifests.
How to apply the manifests produced by kustomize
Use a shell pipe to send the generated YAML from kustomize build into kubectl apply. The pipe (|) forwards stdout of the left-hand command as stdin to the right-hand command.
Example — generate and apply:
kustomize build k8s/renders the combined manifests and prints them to stdout.- The pipe (
|) forwards that YAML tokubectl apply. kubectl apply -f -tellskubectlto read manifests from stdin (the single dash-).kubectlthen creates or updates the resources in the cluster.
kubectl can build and apply a kustomization.yaml directly using the -k flag:
kubectl to read kustomization.yaml from the k8s/ directory, run kustomize, and apply the resulting manifests — combining the build and apply steps above.
-f - means “read manifests from stdin”. Using kustomize build k8s/ | kubectl apply -f - is equivalent to kubectl apply -k k8s/ when applying a local kustomization.Note:
kubectl includes bundled kustomize support, but its kustomize version may lag behind the standalone kustomize binary. If you rely on the latest kustomize features, prefer the standalone binary or verify compatibility with your kubectl version.kubectl delete.
Example — delete via pipe:
kubectl’s -k flag directly:
Tips and troubleshooting
- Ensure a
kustomization.yamlfile exists in the target directory (k8s/in the examples). - If
kubectl apply -kfails, check yourkubectlversion and consider using the standalonekustomizebinary. - Use
kustomize build k8s/ > manifests.yamlif you want to inspect the combined output before applying.
kustomize buildonly prints the final manifests; it does not interact with the cluster.- Pipe the output into
kubectlto create/update/delete resources:- Apply:
kustomize build k8s/ | kubectl apply -f -orkubectl apply -k k8s/ - Delete:
kustomize build k8s/ | kubectl delete -f -orkubectl delete -k k8s/
- Apply:
- Use
kubectl apply -k/kubectl delete -kwhen you wantkubectlitself to run kustomize; prefer the standalone binary if you need the latest kustomize features.