# Hands-On GitOps Patterns for Helm Users 1. Install Flux CLI and Kind: ```console $ brew reinstall flux kind $ kind --version && flux --version kind version 0.11.1 flux version 0.25.3 ``` 2. Make Personal Access Token for creating repositories 1. [Generate new token]() 2. Check all permissions under repo 3. Copy PAT to buffer 3. Export env vars locally I've done this in advance. Use `read -s` during demo ```console $ export GITHUB_TOKEN=[paste PAT] $ echo $GITHUB_TOKEN | wc -c 41 ``` 4. Create local demo cluster ```console $ kind create cluster (took 40s) ``` 5. 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 ```console $ flux bootstrap github \ --owner scottrigby --personal \ --repository flux-for-helm-users \ --branch main \ --path=clusters/dev (output) 6. Clone the newly created git repo to your local workspace ```console $ cd ~/code/github.com/scottrigby \ && git clone git@github.com: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 ``` 7. Lets create a Helm release the most common way, using the Helm CLI ```console $ 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' ``` 8. Now lets convert that to declarative CRs that Flux understands It's very easy with these commands: ```console $ 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' ``` 9. 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 repo` use `flux create source helm`: ```console $ 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 ``` 10. From this point on, you are now doing GitOps: ```console $ git add . $ git commit -m 'Configure podinfo Helm Repo source and app1 Helm Release' $ git push ``` 11. Cleanup demo cluster ```console $ kind delete cluster ```