> ## 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 apply and delete Kubernetes resources using Kustomize and kubectl commands.

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:

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

   ```bash theme={null}
   kustomize build k8s/ | kubectl apply -f -
   ```

   Example output:

   ```bash theme={null}
   service/nginx-loadbalancer-service created
   deployment.apps/nginx-deployment created
   ```

2. **Using `kubectl`’s native Kustomize support with the `-k` flag:**

   ```bash theme={null}
   kubectl apply -k k8s/
   ```

   Example output:

   ```bash theme={null}
   service/nginx-loadbalancer-service created
   deployment.apps/nginx-deployment created
   ```

<Callout icon="lightbulb" color="#1CB2FE">
  Using `kubectl apply -k` automatically detects your `kustomization.yaml` file in the specified directory—no need to pipe output manually.
</Callout>

### Command Reference Table

| Command                                      | Description                                        |
| -------------------------------------------- | -------------------------------------------------- |
| `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`:**

   ```bash theme={null}
   kustomize build k8s/ | kubectl delete -f -
   ```

   Example output:

   ```bash theme={null}
   service "nginx-loadbalancer-service" deleted
   deployment.apps "nginx-deployment" deleted
   ```

2. **Using `kubectl delete -k`:**

   ```bash theme={null}
   kubectl delete -k k8s/
   ```

   Example output:

   ```bash theme={null}
   service "nginx-loadbalancer-service" deleted
   deployment.apps "nginx-deployment" deleted
   ```

<Callout icon="triangle-alert" color="#FF6B6B">
  Deleting resources is irreversible. Make sure you’re targeting the correct environment and namespace before running `kubectl delete`.
</Callout>

## Further Reading

* [Kustomize Documentation](https://kubectl.docs.kubernetes.io/references/kustomize/)
* [kubectl apply Overview](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply)
* [kubectl delete Overview](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#delete)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/kustomize/module/8b591384-c5e2-4411-afc1-443d3f2ba735/lesson/dc9f311c-23c3-4eb8-b8be-3ffaadc1fa12" />
</CardGroup>
