Certified Kubernetes Application Developer - CKAD

2025 Updates Kustomize Basics

Kustomize Output

In the previous lesson, we explored the Kustomize build command. This command collects all your resource configurations, applies the necessary transformations, and outputs the final configurations to the console. Remember that these configurations are not automatically deployed to your Kubernetes cluster. Running commands like kubectl get pods, kubectl get deployments, or kubectl get services will not show any new resources until you explicitly apply them.

Important

The output from Kustomize build is solely for previewing your final configuration. To deploy these changes, you must apply them using kubectl.

Deploying Configurations

To deploy the configurations generated by Kustomize, you can pipe its output directly into kubectl apply using the Linux pipe (|) operator. This operator takes the output of one command and passes it as input to the next command. Below is an example demonstrating this approach:

$ kustomize build k8s/ | kubectl apply -f -
service/nginx-loadbalancer-service created
deployment.apps/nginx-deployment created

This multi-step command performs the following tasks:

  1. Runs kustomize build k8s/ to generate the final configuration.
  2. Pipes the output to kubectl apply -f -, which applies the configuration to your Kubernetes cluster.

Alternatively, Kubernetes facilitates this process natively with the -k flag, enabling both methods as shown below:

# Using Kustomize with a pipe:
$ kustomize build k8s/ | kubectl apply -f -
service/nginx-loadbalancer-service created
deployment.apps/nginx-deployment created

# Using kubectl directly with the -k flag:
$ kubectl apply -k k8s/
service/nginx-loadbalancer-service created
deployment.apps/nginx-deployment created

Removing Configurations

Deleting the deployed resources follows a process similar to deployment. Simply replace the apply keyword with delete. The first method pipes the output of the Kustomize build command directly into kubectl delete:

$ kustomize build k8s/ | kubectl delete -f -
service "nginx-loadbalancer-service" deleted
deployment.apps "nginx-deployment" deleted

Alternatively, use the native method with the -k flag:

$ kubectl delete -k k8s/
service "nginx-loadbalancer-service" deleted
deployment.apps "nginx-deployment" deleted

Tip

Always verify that the correct configurations are being applied or deleted by reviewing the Kustomize output before proceeding. This helps in avoiding accidental misconfigurations.

Watch Video

Watch video content

Previous
kustomization