Chapter 96: Flux GitOps — Sources, Reconciliation and Safe Local Practice
96.6 Bases, overlays and small patches
Fictional teaching story. At a fictional Nagpur studio, Tara and Hugo want a green lab display without duplicating every common setting.
Why
A small environment-specific change is easier to review than two drifting copies of an entire configuration.
What
Keep shared inputs separate from a small deliberate override.
How
A base and an overlay
A base contains reusable configuration. An overlay composes a base and changes selected fields for one context. This directory layout is a local teaching structure, not an access-control boundary.
Immediate practice example
- Read the example from top to bottom. Do not send it to a real cluster.
base/configmap.yaml
base/kustomization.yaml
overlays/lab/kustomization.yaml
overlays/lab/colour-patch.yaml
- Read the expected result.
Illustrative output: not executed by Flux, kubectl, Helm or Kubernetes.
The lab overlay can reuse the base without copying all of it.
- Understand each line in plain English.
The first file is the harmless ConfigMap. The second lists that file under resources. The third lists ../../base and a patch. The fourth changes only the intended data field. Relative base references can be legitimate in Kustomize; the lab model deliberately does not implement the full path loader or remote-base rules.
A patch changes a selected part
A patch is a small modification to a selected object. Here the target is a ConfigMap name and the changed field is its non-secret colour setting.
Immediate practice example
- Read the example from top to bottom. Do not send it to a real cluster.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
patches:
- path: colour-patch.yaml
- Read the expected result.
Illustrative output: not executed by Flux, kubectl, Helm or Kubernetes.
The overlay includes the base and loads the named patch.
- Understand each line in plain English.
resources selects a directory containing its own local Kustomize file. patches is a list; path identifies the patch file. Do not place these fields in a Flux scheduling object. The patch itself follows immediately below. The real Kustomize merge rules are richer than our Python ConfigMap.data merge.
Read the patch and expected result
A merge combines supported fields from an input and a patch. The target identity here is kind plus metadata.name; actual Kubernetes identity also includes namespace and API context.
Immediate practice example
- Read the example from top to bottom. Do not send it to a real cluster.
apiVersion: v1
kind: ConfigMap
metadata:
name: classroom-colour
data:
colour: green
- Read the expected result.
Illustrative output: not executed by Flux, kubectl, Helm or Kubernetes.
The illustrative composed data contains colour=green instead of blue.
- Understand each line in plain English.
apiVersion, kind and metadata.name identify the intended example object. The data.colour line overrides one harmless string. It does not rename an object or change permissions. Review the complete rendered result before any real deployment; we do not run kubectl apply or a Kustomize engine in this chapter.
Ravindra Bagale's Tip
Small patches reduce duplication; they do not remove the need to review output.
छोट्या patches मुळे duplication कमी होतं; output review तरीही करावा लागतो.
छोटे patches duplication घटाते हैं; output review फिर भी जरूरी है.
Did you understand? Let us try it once more.