Skip to main content
This page documents all Flux Kustomization resources used to manage the cluster configuration with GitOps.

What is a Kustomization?

A Flux Kustomization is a custom resource that tells Flux how to reconcile Kubernetes manifests from a Git repository. It watches a source (like a GitRepository) and applies the manifests found at the specified path.

Core Kustomization Resources

flux-system Kustomization

The root Kustomization that bootstraps the entire cluster:
cluster/kimawesome/flux-system/gotk-sync.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: flux-system
  namespace: flux-system
spec:
  interval: 10m0s
  path: ./cluster/kimawesome
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system
spec.interval
string
required
How often Flux checks the source for changes. Format: 10m0s, 1h, 30s
spec.path
string
required
Path within the Git repository to reconcile. Relative to repository root.
spec.prune
boolean
default:"false"
When true, Flux removes resources from the cluster that are no longer in Git.
spec.sourceRef
object
required
Reference to the source (GitRepository, Bucket, or OCIRepository) containing the manifests.

overlays Kustomization

Manages the environment-specific overlay configurations:
cluster/kimawesome/kustomization.flux.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: overlays
  namespace: flux-system
spec:
  interval: 10m
  path: "./overlays/kimawesome"
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system
This Kustomization applies all environment overlays for the kimawesome cluster.

infrastructure Kustomization

Manages infrastructure components with dependencies:
overlays/kimawesome/infrastructure/kustomization.flux.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: infrastructure
  namespace: flux-system
spec:
  interval: 10m
  path: "./overlays/kimawesome/infrastructure"
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system
  dependsOn:
    - name: metallb
      namespace: kube-system
spec.dependsOn
array
List of Kustomizations or HelmReleases that must be ready before this one is applied.
dependsOn:
  - name: metallb
    namespace: kube-system
  - name: cert-manager
    namespace: cert-manager

Configuration Fields

Source Reference

The sourceRef field tells Flux where to find the manifests:
sourceRef:
  kind: GitRepository
  name: flux-system
  namespace: flux-system  # optional

Health Checks

Configure custom health checks for resources:
spec:
  healthChecks:
    - apiVersion: apps/v1
      kind: Deployment
      name: my-app
      namespace: default
  timeout: 5m

Post-Build Variable Substitution

Use variable substitution in manifests:
spec:
  postBuild:
    substitute:
      CLUSTER_NAME: "kimawesome"
      DOMAIN: "kim.tec.br"
    substituteFrom:
      - kind: ConfigMap
        name: cluster-vars
Then in your manifests:
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  cluster: ${CLUSTER_NAME}
  domain: ${DOMAIN}

Reconciliation Behavior

Automatic Reconciliation

  • Flux checks the source at the interval specified in spec.interval
  • If changes are detected, Flux applies them automatically
  • Resources are created, updated, or deleted based on the manifests

Manual Reconciliation

Force immediate reconciliation:
flux reconcile kustomization flux-system
flux reconcile kustomization overlays --with-source

Suspension

Temporarily stop reconciliation:
flux suspend kustomization infrastructure
flux resume kustomization infrastructure

Dependencies and Ordering

Kustomizations can depend on other Kustomizations or HelmReleases:
spec:
  dependsOn:
    - name: cert-manager
      namespace: cert-manager
    - name: metallb
      namespace: kube-system
Flux ensures dependencies are ready before applying dependent resources.

Common Patterns

Multi-Environment Setup

cluster/
├── base/                 # Base Kustomization
└── production/          # Production overlay Kustomization
    └── staging/         # Staging overlay Kustomization

Namespace Isolation

Each namespace gets its own Kustomization:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: apps-namespace
  namespace: flux-system
spec:
  interval: 10m
  path: ./apps
  prune: true
  targetNamespace: applications
  sourceRef:
    kind: GitRepository
    name: flux-system

Troubleshooting

Check Kustomization Status

flux get kustomizations
kubectl describe kustomization flux-system -n flux-system

View Applied Resources

flux tree kustomization flux-system

Check Events

kubectl get events -n flux-system --sort-by='.lastTimestamp'

Build docs developers (and LLMs) love