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

# The kustomizationyaml File

> Explains the kustomization.yaml file for Kustomize, its purpose, common fields and examples, and how to build and apply customized Kubernetes manifests

Now that Kustomize is installed and configured, this lesson explains the `kustomization.yaml` file: what it is, why it’s required, and how to configure it for common use cases.

In this example repository we have a `k8s/` directory containing two Kubernetes manifests:

* `nginx-deployment.yaml`
* `nginx-service.yaml`

Kustomize does not automatically process every YAML in a folder. Instead, it looks for a single, specific file named `kustomization.yaml` (some Kustomize versions accept `kustomization.yml` or `Kustomization`). Create this file in the directory you want Kustomize to manage.

<Callout icon="lightbulb" color="#1CB2FE">
  The `kustomization.yaml` file tells Kustomize which resources to include and which transformations (labels, patches, image overrides, etc.) to apply. Without it, Kustomize has no entry point.
</Callout>

kustomization.yaml has two primary responsibilities:

1. Declare the Kubernetes resources (manifests) Kustomize should manage.
2. Define the customizations (transformations) to apply to those resources.

Minimal example

Below is a minimal `kustomization.yaml` that includes the two manifests and applies a common label across all resources:

```yaml theme={null}
# kubernetes resources to be managed by kustomize
resources:
  - nginx-deployment.yaml
  - nginx-service.yaml

# Customizations that need to be made
commonLabels:
  company: KodeKloud
```

How this works

* The `resources` list enumerates each manifest file that Kustomize will read and include in the build.
* The `commonLabels` entry instructs Kustomize to add `company: KodeKloud` to every resource included in the generated output.

What else can you put in kustomization.yaml?

Kustomize supports many transformations. Here are common fields you will see in kustomization files:

| Field | Use case | Example |
| - | - | - |
| `resources` | List the manifest files or directories to include | `- nginx-deployment.yaml` |
| `commonLabels` | Add the same label to all resources | `company: KodeKloud` |
| `namePrefix` / `nameSuffix` | Add a prefix/suffix to resource names for environment isolation | `namePrefix: dev-` |
| `images` | Override image names, tags, or digests | `- name: nginx\n  newTag: "1.21.3"` |
| `patchesStrategicMerge` | Apply strategic merge patches to resources | `- nginx-deployment-patch.yaml` |
| `vars` | Define variables to substitute into resource manifests | `varName: MY_VAR` |

Note: When including examples with braces or other special characters in tables or inline examples, wrap them in backticks (e.g., `[{ "object": "person" }]`) so MDX parsers don’t interpret them.

Running Kustomize

To build the final manifest YAML from a kustomization directory, run:

```bash theme={null}
kustomize build k8s
```

What happens when you run this command:

* Kustomize reads `k8s/kustomization.yaml`.
* It imports the files listed in `resources`.
* It applies the transformations declared in the kustomization file.
* It prints the final YAML to stdout.

Important: `kustomize build` generates the manifests but does not apply them to a Kubernetes cluster. To apply the generated manifests, pipe the output into `kubectl`:

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

Or let `kubectl` perform the kustomize build and apply in one step:

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

This uses your current kubeconfig context to create or update resources in the cluster.

Example build output

After running `kustomize build k8s`, the output will include both the Service and the Deployment manifests with the added label. For example:

```yaml theme={null}
# excerpt from Kustomize build output
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    company: KodeKloud
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    company: KodeKloud
...
```

Best practices and tips

* Keep your `kustomization.yaml` focused: list only the resources you intend to manage in that kustomization directory.
* Use `namePrefix` or `nameSuffix` to avoid naming collisions across environments.
* Prefer `patchesStrategicMerge` or JSON patches for environment-specific modifications rather than maintaining duplicate manifests.
* For complex setups, break overlays into separate directories (base + overlays) and reference them via `resources` or `bases`.

References and further reading

* Kustomize official docs: [https://kustomize.io/](https://kustomize.io/)
* Kubernetes documentation: [https://kubernetes.io/docs/](https://kubernetes.io/docs/)

Summary

* Kustomize looks for `kustomization.yaml` in the directory you point it to.
* That file declares (a) the list of resource manifests to include and (b) the customizations/transformations to apply.
* Use `kustomize build <dir>` to produce the final YAML and pipe it to `kubectl apply -f -` or use `kubectl apply -k <dir>` to apply directly.

<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/c0dec2bd-e98d-49ce-acce-f7e419016593" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.