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

# Managing Directories

> This article explains how to manage Kubernetes manifests using Kustomize, including directory structures and deployment commands.

Even with a minimal `kustomization.yaml`, Kustomize lets you orchestrate Kubernetes manifests across many folders—no extra scripting required.

## Flat Directory Structure

When you start small, a single directory often suffices:

```text theme={null}
k8s/
├── api-depl.yaml
├── api-service.yaml
├── db-depl.yaml
└── db-service.yaml
```

To deploy all resources at once:

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

This is plain Kubernetes—no Kustomize features yet.

## Introducing Subdirectories

As your manifest count grows, you might split them:

```text theme={null}
k8s/
├── api/
│   ├── api-depl.yaml
│   └── api-service.yaml
└── db/
    ├── db-depl.yaml
    └── db-service.yaml
```

Now deployment requires two commands:

```bash theme={null}
kubectl apply -f k8s/api/
kubectl apply -f k8s/db/
```

<Callout icon="triangle-alert" color="#FF6B6B">
  Manually running `kubectl apply` in each subfolder can be error-prone and difficult to automate in CI/CD.
</Callout>

## Single Root kustomization.yaml

Instead of listing directories every time, create a single `kustomization.yaml` at `k8s/`:

```yaml theme={null}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - api/api-depl.yaml
  - api/api-service.yaml
  - db/db-depl.yaml
  - db/db-service.yaml
```

Then deploy with one of these commands:

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

<Callout icon="lightbulb" color="#1CB2FE">
  `kubectl apply -k` invokes Kustomize natively—you don’t need the standalone binary.
</Callout>

## When the Resource List Grows

Adding more services (e.g., `cache/`, `kafka/`) quickly makes the root manifest unwieldy:

```text theme={null}
k8s/
├── api/
├── db/
├── cache/
│   ├── redis-config.yaml
│   ├── redis-depl.yaml
│   └── redis-service.yaml
└── kafka/
    ├── kafka-config.yaml
    ├── kafka-depl.yaml
    └── kafka-service.yaml
```

A flat list of ten or more files in one `kustomization.yaml` is hard to maintain.

## Nested kustomization.yaml Files

A cleaner pattern is to give each subdirectory its own `kustomization.yaml`:

**`k8s/api/kustomization.yaml`**

```yaml theme={null}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - api-depl.yaml
  - api-service.yaml
```

**`k8s/db/kustomization.yaml`**

```yaml theme={null}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - db-depl.yaml
  - db-service.yaml
```

Repeat for `cache/` and `kafka/`. Then simplify your root `kustomization.yaml`:

```yaml theme={null}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - api/
  - db/
  - cache/
  - kafka/
```

Deploy everything in one go:

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

This hierarchical layout keeps the root file concise and scales seamlessly.

## Command Reference

| Layout                    | Command                                      |
| ------------------------- | -------------------------------------------- |
| Flat folder               | `kubectl apply -f k8s/`                      |
| Single-root Kustomization | `kubectl apply -k k8s/`                      |
| Build then apply          | `kustomize build k8s/ \| kubectl apply -f -` |

## Links and References

* [Kustomize Documentation](https://kubectl.docs.kubernetes.io/references/kustomize/)
* [kubectl apply](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply)
* [Kubernetes Manifests Guide](https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/)

<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/4b621de0-dbb3-4f3c-a60b-6abfe7ba9e83" />
</CardGroup>
