Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 58Flux CD · Git and CI/CD

Install and set up Flux CD (GitOps)

Flux keeps a Kubernetes cluster in sync with Git, the GitOps way — like Argo CD, but built as a set of small Kubernetes controllers with no UI of its own. Flux bootstraps itself into Git (its own config lives in the repo it watches), applies Kustomize folders and Helm charts, decrypts SOPS secrets, and can even update image tags in Git. This guide installs the Flux CLI, bootstraps a cluster with GitHub, adds an app and a HelmRelease, and covers the daily commands and fixes.

  • 10 Lessen
  • 9 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

58.1

Know it before you install

Sources fetch things (GitRepository, OCIRepository, HelmRepository). Kustomizations (Flux objects, not the kustomize file) apply a path from a source to the cluster on an interval. HelmReleases install charts. Each is reconciled by its controller: source-controller, kustomize-controller, helm-controller, notification-controller (and image automation controllers if you want them).

ItemValue
CLIflux
Namespaceflux-system
Git layoutclusters/<cluster>/ (Flux's own config and the entry Kustomizations)
ObjectsGitRepository, Kustomization, HelmRepository, HelmRelease, Alert, ImagePolicy …
Secrets in GitSOPS (age or cloud KMS), decrypted by kustomize-controller

Commando's in deze les

58.2

Install the CLI (RHEL and Ubuntu)

curl -s https://fluxcd.io/install.sh -o flux-install.sh
less flux-install.sh
bash flux-install.sh
flux --version
flux version 2.7.3
echo '. <(flux completion bash)' >> ~/.bashrc
flux check --pre
✔ Kubernetes 1.33.5 >=1.32.0-0
✔ prerequisites checks passed

58.3

Bootstrap the cluster with GitHub

Bootstrap creates (or uses) a repository, commits Flux's manifests to clusters/prod, installs Flux, and makes Flux watch that path. Use a token with repo rights (or a GitHub App):

export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx
flux bootstrap github --owner=ORG --repository=fleet --branch=main --path=clusters/prod --personal=false --read-write-key=false
► connecting to github.com
✔ repository "https://github.com/ORG/fleet" created
✔ reconciled components
✔ all components are healthy
flux check
kubectl -n flux-system get pods

Flux makes a read-only deploy key for the repository; the token is only used for the bootstrap. (GitLab: flux bootstrap gitlab; any Git server: flux bootstrap git --url=ssh://….)

58.4

First configuration: add an app

A source for the app's deploy repo and a Kustomization that applies ./deploy/prod from it:

flux create source git shop --url=https://github.com/ORG/shop-deploy --branch=main --interval=1m --export > clusters/prod/shop-source.yaml
flux create kustomization shop --source=GitRepository/shop --path="./deploy/prod" --prune=true --interval=5m --target-namespace=shop --wait=true --export > clusters/prod/shop-kustomization.yaml
git add clusters/prod && git commit -m "Add shop" && git push
flux reconcile kustomization flux-system --with-source
flux get kustomizations
NAME          REVISION              READY   MESSAGE
flux-system   main@sha1:4f2c1a9e    True    Applied revision: main@sha1:4f2c1a9e
shop          main@sha1:a81b0c37    True    Applied revision: main@sha1:a81b0c37
SettingWhy
--prune=trueObjects removed from Git are removed from the cluster.
--intervalHow often Flux checks (add webhooks for instant sync).
--wait=trueThe Kustomization is Ready only when the workloads are healthy.
Commit the generated YAMLEverything — even Flux's own config — lives in Git.

A Helm chart, the GitOps way:

clusters/prod/cert-manager.yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
  name: jetstack
  namespace: flux-system
spec:
  interval: 12h
  url: https://charts.jetstack.io
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: cert-manager
  namespace: cert-manager
spec:
  interval: 30m
  chart:
    spec:
      chart: cert-manager
      version: "1.19.x"
      sourceRef:
        kind: HelmRepository
        name: jetstack
        namespace: flux-system
  install:
    remediation: { retries: 3 }
  upgrade:
    remediation: { retries: 3, remediateLastFailure: true }
  values:
    crds:
      enabled: true

58.5

Secrets with SOPS

Encrypt Secrets in Git with an age key; Flux decrypts them in the cluster:

age-keygen -o age.agekey
kubectl -n flux-system create secret generic sops-age --from-file=age.agekey=age.agekey
sops --encrypt --age AGE_PUBLIC_KEY --encrypted-regex '^(data|stringData)$' --in-place deploy/prod/db-secret.yaml

Add decryption: {provider: sops, secretRef: {name: sops-age}} to the Kustomization. Keep the age.agekey file out of Git (store it in a password manager / KMS).

58.6

Daily use: the commands and the real uses

flux get all -A
flux get sources git
flux get helmreleases -A
flux reconcile kustomization shop --with-source
flux suspend kustomization shop
flux resume kustomization shop
flux logs --level=error --since=1h
flux events -n flux-system
flux tree kustomization shop
flux diff kustomization shop --path ./deploy/prod

suspend stops syncing (for an emergency hotfix); resume starts it again — the cluster then goes back to what Git says.

Real uses at work:

  • Many clusters from one "fleet" repo (clusters/dev, clusters/prod), with shared infrastructure/ and apps/ folders.
  • Platform add-ons as HelmReleases; app teams deploy by merging to their deploy repo.
  • Image automation: Flux updates the image tag in Git when a new version is pushed.
  • Alerts to Slack/Teams on failed reconciles (Provider + Alert objects).

Commando's in deze les

58.7

Make it safe

Security checklist:

  • Read-only deploy keys; the bootstrap token short-lived and not stored.
  • Branch protection on the fleet repo — Git is production access.
  • SOPS for all secrets; the decryption key only in the cluster and a safe store.
  • Multi-tenancy: per-team Kustomizations with serviceAccountName and limited RBAC.
  • Pin chart versions (or narrow ranges) and image tags; review changes in pull requests.
  • Keep Flux updated (flux bootstrap again with the new CLI version).

Commando's in deze les

58.8

Update and remove

bash flux-install.sh
flux bootstrap github --owner=ORG --repository=fleet --branch=main --path=clusters/prod
flux uninstall --keep-namespace=false

Running bootstrap again with a newer CLI upgrades the controllers (and commits the new manifests). flux uninstall removes Flux but leaves your apps running.

58.9

Fix common problems

ProblemCauseFix
Kustomization: kustomization path not foundWrong path in the Kustomization.Check the folder name in Git; paths start with ./.
Source: authentication required / unable to cloneDeploy key missing or wrong URL.flux get sources git; check the key in the repo settings; SSH vs HTTPS URL.
HelmRelease upgrade retries exhaustedThe chart upgrade fails (values, immutable field).flux logs --kind=HelmRelease; kubectl describe helmrelease; fix values; flux reconcile hr NAME --force.
Changes in Git are not appliedInterval not reached, or the Kustomization is suspended.flux reconcile … --with-source; flux get kustomizations (SUSPENDED?).
Decryption fails: sops: failed to decryptWrong or missing age key secret.Check the sops-age secret and the public key used.
dependency 'flux-system/infra' is not readyA dependsOn target is failing.Fix the dependency first; flux tree.

58.10

Next steps

1What does flux bootstrap put in Git?

Flux's own manifests and sync config under the chosen path, so Flux manages itself from Git.

2How do you stop Flux from undoing an emergency hotfix for a while?

flux suspend kustomization NAME — then put the fix in Git and flux resume.

Alle commando's in dit hoofdstuk