Skip to content

Deploying

Flux runs in the cluster with its source and Helm controllers: a tenant deploys a Helm chart by declaring, in its own namespace, where the chart comes from and a HelmRelease. There is no kustomize controller: no Kustomization objects; plain manifests go in a chart (a Chart.yaml and a templates/ directory).

The objects

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata: {name: my-app, namespace: my-app}
spec:
  url: ssh://git@github.com/example/my-app.git
  ref: {branch: main}
  interval: 1m
  secretRef: {name: my-app-git}          # a deploy key (below); none for a public repository over https
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata: {name: my-app, namespace: my-app}
spec:
  interval: 5m
  serviceAccountName: flux               # required
  chart:
    spec:
      chart: deploy/chart                # the chart's path in the repository
      reconcileStrategy: Revision        # every commit, not only a new chart version
      sourceRef: {kind: GitRepository, name: my-app}
  valuesFiles: [deploy/chart/values.yaml, deploy/values/prod.yaml]
  • serviceAccountName: flux: the namespace's service account Flux acts as, with the rights of the namespace's admin. A release naming none acts as the namespace's default, which has no rights: it fails.
  • Everything in the namespace: a sourceRef (or a values Secret) of another namespace is refused.
  • Sources: GitRepository, OCIRepository (a chart pushed as an OCI artifact) and HelmRepository work alike.
  • The Flux objects themselves are applied once by a member (kubectl apply -f deploy/flux.yaml), then live in the application's repository like the rest.

A deploy key

For a private repository over SSH, a read-only deploy key of the repository and the host's key:

ssh-keygen -t ed25519 -N '' -C my-app-flux -f deploy-key
kubectl -n my-app create secret generic my-app-git \
  --from-file=identity=deploy-key --from-file=identity.pub=deploy-key.pub \
  --from-literal=known_hosts="$(ssh-keyscan github.com 2>/dev/null)"

The public key goes to the repository's deploy keys (read-only); the private one stays in the Secret only.

Day to day

  • A deployment is a commit: the version the release deploys (an image tag or digest in a values file) changed and pushed. Promotion between namespaces (my-app-staging, then my-app) is the same commit to another values file.
  • Now rather than at the next interval: kubectl -n my-app annotate gitrepository my-app reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite.
  • State: kubectl -n my-app get gitrepository,helmrelease (READY, and the message when it isn't); kubectl -n my-app describe helmrelease my-app for the last attempts.
  • A single-instance application with a volume (ReadWriteOnce): strategy: {type: Recreate} in its Deployment. A rolling update would start the new pod before the old one released the volume, and wait.

Without Flux

helm upgrade --install with a member's kubeconfig works too, in the namespace; Flux's way keeps the cluster equal to the repository.