kustomize build, it compiles all resource manifests along with their specified transformations and prints them to stdout. However, this command alone does not apply these configurations to your Kubernetes cluster. If you immediately check your cluster with:
Applying Resources
There are two common ways to apply the manifests generated by Kustomize:-
Piping the output into
kubectl apply:Example output: -
Using
kubectl’s native Kustomize support with the-kflag:Example output:
Using
kubectl apply -k automatically detects your kustomization.yaml file in the specified directory—no need to pipe output manually.Command Reference Table
| Command | Description |
|---|---|
kustomize build k8s/ | Generate and print manifests to stdout |
kustomize build k8s/ | kubectl apply -f - | Apply Kustomize-generated manifests via shell pipe |
kubectl apply -k k8s/ | Apply a directory of Kustomize manifests natively |
Deleting Resources
To remove the same set of resources you applied, replaceapply with delete in either approach:
-
Piping into
kubectl delete:Example output: -
Using
kubectl delete -k:Example output:
Deleting resources is irreversible. Make sure you’re targeting the correct environment and namespace before running
kubectl delete.