-
Install Flux CLI and Kind:
$ brew reinstall flux kind $ kind --version && flux --version kind version 0.11.1 flux version 0.25.3
-
Make Personal Access Token for creating repositories
- Generate new token
- Check all permissions under repo
- Copy PAT to buffer
-
Export env vars locally
I've done this in advance. Use
read -sduring demo$ export GITHUB_TOKEN=[paste PAT] $ echo $GITHUB_TOKEN | wc -c 41
-
Create local demo cluster
$ kind create cluster (took 40s)
-
Simple bootstrap:
the more complex your org is, the more complex your directory structure and patterns are
there is no gold standard
flux is not opinionated about how directories are structured, rather it tries to be as flexible as possible to accommodate different patterns
$ flux bootstrap github \ --owner scottrigby --personal \ --repository flux-for-helm-users \ --branch main \ --path=clusters/dev (output)
-
Clone the newly created git repo to your local workspace
$ cd ~/code/github.com/scottrigby \ && git clone [email protected]:scottrigby/flux-for-helm-users.git \ && cd flux-for-helm-users $ tree . └── clusters └── dev └── flux-system ├── gotk-components.yaml ├── gotk-sync.yaml └── kustomization.yaml 3 directories, 3 files
-
Lets create a Helm release the most common way, using the Helm CLI
$ helm repo add podinfo https://stefanprodan.github.io/podinfo
$ helm upgrade -i my-release podinfo/podinfo \
--set replicaCount=2 \
--set logLevel=debug \
--set serviceMonitor.interval=10s \
--set ui.color='#fa0087'- Now lets convert that to declarative CRs that Flux understands
It's very easy with these commands:
$ helm get values my-release -oyaml > my-values.yaml
$ cat values.yaml
logLevel: debug
replicaCount: 2
serviceMonitor:
interval: 10s
ui:
color: '#fa0087'
$ flux create helmrelease app1 \
--interval=10m \
--source=HelmRepository/podinfo \
--chart=podinfo \
--chart-version=">4.0.0" \
--values my-values.yaml \
--export > ./clusters/dev/podinfo-helmrelease.yaml
$ cat clusters/dev/podinfo-helmrelease.yaml
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: app1
namespace: flux-system
spec:
chart:
spec:
chart: podinfo
sourceRef:
kind: HelmRepository
name: podinfo
version: '>4.0.0'
interval: 10m0s
values:
logLevel: debug
replicaCount: 2
serviceMonitor:
interval: 10s
ui:
color: '#fa0087'-
Create a Source Custom Resource locally
The Helm CLI reads your local repo info (created in step 7), but the Flux Helm controller in your cluster needs this info too. Provide it with another CRD. Flux makes this easy as well. Instead of
helm add repouseflux create source helm:$ flux create source helm podinfo \ --url=https://stefanprodan.github.io/podinfo \ --interval=10m \ --export > clusters/dev/source-helmrepo-podinfo.yaml $ cat clusters/dev/source-helmrepo-podinfo.yaml --- apiVersion: source.toolkit.fluxcd.io/v1beta1 kind: HelmRepository metadata: name: podinfo namespace: flux-system spec: interval: 10m0s url: https://stefanprodan.github.io/podinfo
-
From this point on, you are now doing GitOps:
$ git add . $ git commit -m 'Configure podinfo Helm Repo source and app1 Helm Release' $ git push
-
Cleanup demo cluster
$ kind delete cluster
Step 10, the command needs the namespace identifier
flux reconcile helmrelease $FLUX_HELM_RELEASE_RESOURCE -n default
Thanks.