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

# Demo Kustomize Controller Kustomize Overlay

> Using Flux Kustomization to apply a Git-stored Kustomize overlay directly, showing GitRepository and Kustomization setup and Flux reconciliation of manifests.

This lesson shows how to use a Kustomization resource that points at an existing `kustomization.yaml` (a Kustomize overlay) stored in a Git branch. When the Kustomization references a path that already contains an overlay, the Kustomize Controller will validate and apply the manifests directly — skipping overlay generation — which simplifies your GitOps workflow.

Overview — what you will do:

* Switch to the `3-demo` branch (this branch contains a `kustomization.yaml` and plain Kubernetes manifests).
* Create a Flux `GitRepository` source that references the `3-demo` branch.
* Create a Flux `Kustomization` that points to the overlay path in that source.
* Observe Flux fetching the branch and applying the namespace and application resources.

## 1. Switch to the 3-demo branch

Checkout the branch that contains the overlay and the manifests:

```bash theme={null}
# from your local bb-app-source repository
git checkout 3-demo
# Example output:
# Branch '3-demo' set up to track remote branch '3-demo' from 'origin'.
# Switched to branch '3-demo'
```

On this branch the repository contains, for example in `./kustomize`:

* `deployment.yml`
* `service.yml`
* `namespace.yml`
* `kustomization.yaml`

Example `kustomization.yaml` (overlay file) in the repo:

```yaml theme={null}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yml
  - service.yml
  - namespace.yml
```

When a Kustomization resource points at a Git source path that already includes a `kustomization.yaml` (or a `kustomize` directory with an overlay), Flux will use that overlay directly and will not generate a separate overlay.

## 2. Create a GitRepository source (Flux)

From your Flux cluster repo directory (for example `block-buster/flux-clusters/dev-cluster`) create a `GitRepository` resource that references the `3-demo` branch and export it to YAML:

```bash theme={null}
flux create source git 3-demo-source-git-bb-app \
  --url https://github.com/sidd-harth-2/bb-app-source \
  --branch 3-demo \
  --interval 10s \
  --export > 3-demo-source-git-bb-app.yml
```

The exported `GitRepository` YAML will look like:

```yaml theme={null}
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: GitRepository
metadata:
  name: 3-demo-source-git-bb-app
  namespace: flux-system
spec:
  interval: 10s
  ref:
    branch: 3-demo
  url: https://github.com/sidd-harth-2/bb-app-source
```

Save and commit `3-demo-source-git-bb-app.yml` to your cluster manifests repository (if you manage Flux configuration in Git), or apply it directly to your cluster so Flux can start reconciling that source.

## 3. Create a Flux Kustomization that points at the overlay

Create a `Kustomization` resource that points to the overlay path (for this example `./kustomize`) and export it:

```bash theme={null}
flux create kustomization 3-demo-kustomize-git-bb-app \
  --source GitRepository/3-demo-source-git-bb-app \
  --path ./kustomize \
  --prune true \
  --interval 10s \
  --target-namespace 3-demo \
  --export > 3-demo-kustomize-git-bb-app.yml
```

The exported `Kustomization` YAML will resemble:

```yaml theme={null}
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: 3-demo-kustomize-git-bb-app
  namespace: flux-system
spec:
  interval: 10s
  path: ./kustomize
  prune: true
  sourceRef:
    kind: GitRepository
    name: 3-demo-source-git-bb-app
  targetNamespace: 3-demo
```

Save and commit `3-demo-kustomize-git-bb-app.yml` to your Flux manifests repository (or apply it) so Flux can reconcile and apply the overlay.

Ensure the `target-namespace` does not conflict with existing resources and that you have appropriate RBAC permissions for Flux to create or manage the specified namespace and resources.

## 4. Observe Flux fetching and applying the overlay

After Flux reconciles the `GitRepository` and `Kustomization`:

Check Git sources:

```bash theme={null}
# show Git sources
flux get sources git
```

Example output:

```bash theme={null}
NAME                         REVISION                   SUSPENDED  READY  MESSAGE
2-demo-source-git-bb-app     2-demo@sha1:7dfa8105       False      True   stored artifact for revision '2-demo@sha1:7dfa8105'
3-demo-source-git-bb-app     3-demo@sha1:990e6de9       False      True   stored artifact for revision '3-demo@sha1:990e6de9'
flux-system                  main@sha1:548f1930         False      True   stored artifact for revision 'main@sha1:548f1930'
```

Check Kustomizations:

```bash theme={null}
# show Kustomizations
flux get kustomizations
```

Example output:

```bash theme={null}
NAME                           REVISION                   SUSPENDED  READY  MESSAGE
2-demo-kustomize-git-bb-app    2-demo@sha1:7dfa8105       False      True   Applied revision: 2-demo@sha1:7dfa8105
3-demo-kustomize-git-bb-app    3-demo@sha1:990e6de9       False      True   Applied revision: 3-demo@sha1:990e6de9
flux-system                    main@sha1:548f1930         False      True   Applied revision: main@sha1:548f1930
```

Verify the namespace and deployed resources:

```bash theme={null}
kubectl get ns
kubectl get all -n 3-demo
```

In this demo branch, the application has a gameplay change: the player starts with three lives instead of one.

![A web screenshot of a "BLOCK BUSTER" breakout-style game showing colored brick rows, a paddle at the bottom and a bouncing ball. The top panel displays pod information like Pod Name, Pod IP, Namespace and app version.](https://mintcdn.com/kodekloud-c4ac6d9a/AyhVWHpoMIYCWiei/images/GitOps-with-FluxCD/Source-and-Kustomize-Controller/Demo-Kustomize-Controller-Kustomize-Overlay/block-buster-breakout-pod-info-screenshot.jpg?fit=max\&auto=format\&n=AyhVWHpoMIYCWiei\&q=85\&s=6a130eb08a8db3480f61fc6eddfa3ecf)

That’s it — because the repo already contained the overlay at the referenced path, the Kustomize Controller applied the manifests directly from the repo: validating and reconciling resources without rebuilding the overlay.

## Quick reference

| Resource | Purpose | Example (export filename) |
| - | - | - |
| GitRepository | Points Flux to the Git branch containing overlay and manifests | `3-demo-source-git-bb-app.yml` |
| Kustomization | Tells Flux which path to apply from the Git source and how to apply it | `3-demo-kustomize-git-bb-app.yml` |

Further reading:

* Flux Kustomize Controller: [https://fluxcd.io/docs/components/kustomize/](https://fluxcd.io/docs/components/kustomize/)
* Flux GitRepository docs: [https://fluxcd.io/docs/components/source/gitrepository/](https://fluxcd.io/docs/components/source/gitrepository/)
* Kustomize documentation: [https://kubectl.docs.kubernetes.io/references/kustomize/](https://kubectl.docs.kubernetes.io/references/kustomize/)

> **[Watch Video](https://learn.kodekloud.com/user/courses/gitops-with-fluxcd/module/857e34cf-a086-433b-bf3b-88a5a5096a6f/lesson/8791b8c0-ec22-4a50-bf64-ae3960f562a5)**

> **[Practice Lab](https://learn.kodekloud.com/user/courses/gitops-with-fluxcd/module/857e34cf-a086-433b-bf3b-88a5a5096a6f/lesson/4670f553-12cb-4b1a-a901-37f9b1e32e38)**


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