Flux Architecture & Bootstrap
Flux (CNCF graduated, like Argo CD) takes a different shape. There is no central server and, out of the box, no UI: Flux is a set of small, independent controllers, each owning a few CRDs, that cooperate through Kubernetes objects. You drive it with kubectl, the flux CLI and, above all, Git. This course uses Flux 2.x (the CLI in the examples is 2.10).
The GitOps Toolkit
┌──────────────────────────── flux-system ────────────────────────────┐
Git, OCI, │ source-controller GitRepository, OCIRepository, HelmRepository, │
Helm repos, ───>│ fetches, verifies, HelmChart, Bucket -> stores an "artifact" │
S3 buckets │ packages artifacts (tarball + revision) served over HTTP │
│ │ artifact │
│ ├──> kustomize-controller Kustomization: build + apply + │──> cluster
│ │ prune + health checks │
│ └──> helm-controller HelmRelease: helm install/upgrade │──> cluster
│ notification-controller Alerts/Providers out (Slack...), Receivers in │
│ image-reflector + image-automation (optional): scan registries, commit │──> Git
└─────────────────────────────────────────────────────────────────────────┘| Controller | CRDs | Job |
|---|---|---|
| source-controller | GitRepository, OCIRepository, HelmRepository, HelmChart, Bucket, ExternalArtifact (ArtifactGenerator comes with the optional source-watcher component) |
fetch sources on an interval, verify signatures, publish each revision as an artifact |
| kustomize-controller | Kustomization |
build the artifact with Kustomize, decrypt SOPS, apply with server-side apply, prune, wait for health |
| helm-controller | HelmRelease |
real Helm installs and upgrades, with tests, rollback and drift detection |
| notification-controller | Provider, Alert, Receiver |
send events out; accept webhooks in (to reconcile immediately on push) |
| image-reflector-controller, image-automation-controller | ImageRepository, ImagePolicy, ImageUpdateAutomation |
find new image tags and commit them to Git (Image Automation) |
Note the naming clash: a Flux Kustomization (kustomize.toolkit.fluxcd.io/v1) is a CRD that tells the controller to build a path; the kustomization.yaml file (kustomize.config.k8s.io) is Kustomize's own config. A Flux Kustomization usually points at a folder containing a kustomization.yaml.
The install manifests are just YAML
flux install --export prints everything Flux installs, without touching a cluster. It is a convenient way to see the moving parts, and it is what bootstrap commits to Git:
flux install --export --components-extra=image-reflector-controller,image-automation-controller > gotk-components.yaml
head -n 4 gotk-components.yaml
echo "--- controllers:"
yq -N 'select(.kind == "Deployment") | .spec.template.spec.containers[0].image' gotk-components.yaml
echo "--- CRDs by API group:"
yq -N 'select(.kind == "CustomResourceDefinition") | .spec.group' gotk-components.yaml | sort | uniq -c---
# This manifest was generated by flux. DO NOT EDIT.
# Flux Version: v2.10.0
# Components: source-controller,kustomize-controller,helm-controller,notification-controller,image-reflector-controller,image-automation-controller
--- controllers:
ghcr.io/fluxcd/source-controller:v1.10.1
ghcr.io/fluxcd/kustomize-controller:v1.10.1
ghcr.io/fluxcd/helm-controller:v1.7.1
ghcr.io/fluxcd/notification-controller:v1.10.0
ghcr.io/fluxcd/image-reflector-controller:v1.3.0
ghcr.io/fluxcd/image-automation-controller:v1.3.0
--- CRDs by API group:
1 helm.toolkit.fluxcd.io
3 image.toolkit.fluxcd.io
1 kustomize.toolkit.fluxcd.io
3 notification.toolkit.fluxcd.io
6 source.toolkit.fluxcd.io
Bootstrap: Flux manages itself
flux bootstrap installs Flux and commits its own manifests to your repository, then points Flux at that repository. From then on, upgrading Flux is a commit too. A sample session against GitHub (it needs a cluster and a token, so it isn't run here):
export GITHUB_TOKEN=<fine-grained token with repo admin rights on acme/linkly-deploy>
flux check --pre
flux bootstrap github \
--owner=acme --repository=linkly-deploy --branch=main \
--path=./clusters/productionSample output of the bootstrap (flux check --pre first prints the cluster version and the minimum this Flux release supports):
► connecting to github.com
✔ repository "https://github.com/acme/linkly-deploy" cloned
✚ generating manifests
✔ components manifests pushed
► installing components in flux-system namespace
deployment "source-controller" successfully rolled out
deployment "kustomize-controller" successfully rolled out
deployment "helm-controller" successfully rolled out
deployment "notification-controller" successfully rolled out
✔ install completed
► configuring deploy key
✔ deploy key configured
► generating sync manifests
✔ sync manifests pushed
► applying sync manifests
◎ waiting for cluster sync
✔ bootstrap finishedBootstrap adds clusters/production/flux-system/ with three files:
| File | Contents |
|---|---|
gotk-components.yaml |
the controllers and CRDs (the export above) |
gotk-sync.yaml |
a GitRepository named flux-system for this repo and a Kustomization named flux-system that applies ./clusters/production |
kustomization.yaml |
lists the two files |
The flux-system Kustomization reconciles the whole clusters/production folder, including flux-system/ itself, so every other Flux object you add there (sources, Kustomizations, HelmReleases) is picked up automatically: Flux's built-in equivalent of app of apps. Bootstrap also works with GitLab, Bitbucket, Gitea and plain Git (flux bootstrap git --url=ssh://…).
You can reproduce gotk-sync.yaml offline with the same flux create … --export commands bootstrap uses internally:
flux create source git flux-system --url=ssh://git@github.com/acme/linkly-deploy --branch=main \
--secret-ref=flux-system --interval=1m --export > gotk-sync.yaml
flux create kustomization flux-system --source=GitRepository/flux-system \
--path=./clusters/production --prune=true --interval=10m --export >> gotk-sync.yaml
kubeconform -strict -summary gotk-sync.yaml
yq -N '.kind + "/" + .metadata.name + " interval=" + .spec.interval' gotk-sync.yamlSummary: 2 resources found in 1 file - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0
GitRepository/flux-system interval=1m0s
Kustomization/flux-system interval=10m0s
Alternatives to bootstrap
- Flux Operator (by ControlPlane, the company employing several Flux maintainers): a
FluxInstanceobject declares the Flux version and components, and the operator installs and upgrades Flux. Handy when clusters are created by Terraform or Cluster API. - Terraform: the
fluxcd/fluxprovider runs bootstrap from IaC. - Helm: community charts exist, but then Helm, not Git, owns Flux.
Test yourself
Which Flux controller fetches Git repositories and turns each revision into an artifact?
- kustomize-controller
- source-controller
- helm-controller
- notification-controller
What is a Flux Kustomization?
- Another name for kustomization.yaml
- A CRD that tells kustomize-controller to build a path from a source and apply, prune and health-check the result
- A Helm values file
- A Kustomize plugin
After flux bootstrap, how do you upgrade Flux?
- Run kubectl apply from your laptop
- Regenerate gotk-components.yaml (e.g.
flux install --export) and commit it; Flux applies its own upgrade - Reinstall the cluster
- Flux upgrades itself from the internet automatically