> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kustomize Output

> This article explains how to deploy and remove Kubernetes resources using Kustomize and kubectl commands.

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.

<Callout icon="lightbulb" color="#1CB2FE">
  The output from Kustomize build is solely for previewing your final configuration. To deploy these changes, you must apply them using `kubectl`.
</Callout>

## 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:

```bash theme={null}
$ 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:

```bash theme={null}
# 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`:

```bash theme={null}
$ 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:

```bash theme={null}
$ kubectl delete -k k8s/
service "nginx-loadbalancer-service" deleted
deployment.apps "nginx-deployment" deleted
```

<Callout icon="lightbulb" color="#1CB2FE">
  Always verify that the correct configurations are being applied or deleted by reviewing the Kustomize output before proceeding. This helps in avoiding accidental misconfigurations.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-kubernetes-application-developer-ckad/module/2503ab74-a871-4b65-a677-7180c001d5c5/lesson/b2ed246e-9cf4-484f-b1e0-8fad82d87034" />
</CardGroup>
