Kustomize

Kustomize Basics

Kustomize Output

When you run 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:

kubectl get pods
kubectl get deployments
kubectl get services

you will see that no resources have been created yet.

Applying Resources

There are two common ways to apply the manifests generated by Kustomize:

  1. Piping the output into kubectl apply:

    kustomize build k8s/ | kubectl apply -f -
    

    Example output:

    service/nginx-loadbalancer-service created
    deployment.apps/nginx-deployment created
    
  2. Using kubectl’s native Kustomize support with the -k flag:

    kubectl apply -k k8s/
    

    Example output:

    service/nginx-loadbalancer-service created
    deployment.apps/nginx-deployment created
    

Note

Using kubectl apply -k automatically detects your kustomization.yaml file in the specified directory—no need to pipe output manually.

Command Reference Table

CommandDescription
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, replace apply with delete in either approach:

  1. Piping into kubectl delete:

    kustomize build k8s/ | kubectl delete -f -
    

    Example output:

    service "nginx-loadbalancer-service" deleted
    deployment.apps "nginx-deployment" deleted
    
  2. Using kubectl delete -k:

    kubectl delete -k k8s/
    

    Example output:

    service "nginx-loadbalancer-service" deleted
    deployment.apps "nginx-deployment" deleted
    

Warning

Deleting resources is irreversible. Make sure you’re targeting the correct environment and namespace before running kubectl delete.

Further Reading

Watch Video

Watch video content

Previous
kustomization