Skip to content

Instantly share code, notes, and snippets.

@scottrigby
Last active September 3, 2025 21:05
Show Gist options
  • Save scottrigby/a1a42c3292ec7899837c578ffdaaf92a to your computer and use it in GitHub Desktop.
Save scottrigby/a1a42c3292ec7899837c578ffdaaf92a to your computer and use it in GitHub Desktop.
GitOps for Helm Users

Hands-On GitOps Patterns for Helm Users

  1. Install Flux CLI and Kind:

    $ 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

    $ export GITHUB_TOKEN=[paste PAT]
    $ echo $GITHUB_TOKEN | wc -c
      41
  4. Create local demo cluster

    $ 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

    $ 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

    $ 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
  7. 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'
  1. 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'
  1. 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:

    $ 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
  2. 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
  3. Cleanup demo cluster

    $ kind delete cluster
@ganadurai
Copy link

Step 10, the command needs the namespace identifier
flux reconcile helmrelease $FLUX_HELM_RELEASE_RESOURCE -n default

Thanks.

@desiby
Copy link

desiby commented Apr 8, 2023

Step 10, the command needs the namespace identifier flux reconcile helmrelease $FLUX_HELM_RELEASE_RESOURCE -n default

Thanks.

yes or put the helm resources in the "flux-system" namespace to make command in step 10 work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment