> ## 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 delete configurations using Kustomize and kubectl in Kubernetes.

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.

<Callout icon="lightbulb" color="#1CB2FE">
  Even though Kustomize outputs the final configuration, you must still deploy it to activate the resources on your cluster.
</Callout>

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

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

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

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

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

<Callout icon="lightbulb" color="#1CB2FE">
  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.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/cka-certification-course-certified-kubernetes-administrator/module/031e84b8-bcbc-4f39-94d6-66d93b05bddc/lesson/b2ed246e-9cf4-484f-b1e0-8fad82d87034" />
</CardGroup>
