CKA Certification Course - Certified Kubernetes Administrator
2025 Updates Kustomize Basics
Kustomize Output
In the previous lesson, we examined the Kustomize build command and its role in transforming resource definitions into final configurations, which are then output to the console. It is important to note that these generated configurations are not automatically deployed to your Kubernetes cluster—running commands like kubectl get pods
, kubectl get deployments
, or kubectl get services
right after the build will not show any new resources.
Important
Even though Kustomize outputs the final configuration, you must still deploy it to activate the resources on your cluster.
Deploying Configurations Using Pipes
To deploy the generated configurations, you can use the Linux pipe utility. This allows you to feed the output of the Kustomize build directly into the Kubernetes API using the kubectl apply
command. Here’s an example:
$ kustomize build k8s/ | kubectl apply -f -
service/nginx-loadbalancer-service created
deployment.apps/nginx-deployment created
In this command, the pipe (|
) directs the output from kustomize build k8s/
into kubectl apply -f -
, thus creating the nginx deployment and its corresponding service.
Deploying Configurations Natively with kubectl
Alternatively, you can accomplish the same deployment natively with kubectl using the -k
flag. This flag tells kubectl to locate and process the kustomization.yaml
file in the specified directory:
$ kubectl apply -k k8s/
service/nginx-loadbalancer-service created
deployment.apps/nginx-deployment created
Both methods will effectively deploy your generated configurations to your Kubernetes cluster.
Deleting Configurations
Removing resources deployed via Kustomize is almost identical to applying them. You simply replace the word apply
with delete
.
Using the Pipe Method
Delete the resources using the pipe method by running:
$ kustomize build k8s/ | kubectl delete -f -
service "nginx-loadbalancer-service" deleted
deployment.apps "nginx-deployment" deleted
Using kubectl with the -k Flag
Or, delete the resources natively with kubectl:
$ kubectl delete -k k8s/
service "nginx-loadbalancer-service" deleted
deployment.apps "nginx-deployment" deleted
Tip
Both methods are effective, so you can choose the one that best fits your workflow. The native kubectl approach with the -k
flag simplifies the process by eliminating the need to use a pipe.
Watch Video
Watch video content