Skip to content

Instantly share code, notes, and snippets.

@scottrigby
Last active February 3, 2023 20:13
Show Gist options
  • Save scottrigby/65c1fbb1f6437f6cfa11b594cf8e26a9 to your computer and use it in GitHub Desktop.
Save scottrigby/65c1fbb1f6437f6cfa11b594cf8e26a9 to your computer and use it in GitHub Desktop.

Flux use case: Cert Manager, Traefik, app with ingress, GitHub as source

Set up local cluster and Flux CLI

  1. Install Flux CLI and Kind:

    $ brew reinstall flux kind
    $ kind --version
    kind version 0.10.0
    $ flux --version
    flux version 0.9.1
  2. Create local demo cluster

    $ kind create cluster
    (took 32s)

Set up for Flux with GitHub as source

  1. Make Personal Access Token for creating repositories

    1. Check all permissions under repo
    2. Copy PAT to buffer
  2. Export env vars locally

    $ read -s GITHUB_TOKEN
    [paste PAT]
    $ export GITHUB_TOKEN=$GITHUB_TOKEN

Bootstrap Flux both for your source and in cluster

  1. Simple bootstrap:

    $ flux bootstrap github --owner scottrigby --personal \
    --repository ggg-demo \
    --path=flux/boot
    ► connecting to github.com
    ✔ repository created
    ✔ repository cloned
    ✚ generating manifests
    ✔ components manifests pushed
    ► installing components in flux-system namespace
    
    ◎ verifying installation
    ✔ install completed
    ► configuring deploy key
    ✔ deploy key configured
    ► generating sync manifests
    ✔ sync manifests pushed
    ► applying sync manifests
    ◎ waiting for cluster sync
    ✔ bootstrap finished
    (took 39s)
  2. Clone the newly created git repo to your local workspace

    $ cd ~/code/github.com/scottrigby
    $ git clone git@github.com:scottrigby/ggg-demo.git
    $ tree
    .
    ├── README.md
    └── flux
        └── boot
            └── flux-system
                ├── gotk-components.yaml
                ├── gotk-sync.yaml
                └── kustomization.yaml

Declare Traefik for Ingress Control

  1. Create a namespace if you wish for Traefik (files can be organized however you like)

    $ mkdir flux/boot/traefik
    $ echo 'apiVersion: v1
    kind: Namespace
    metadata:
      name: traefik' > flux/boot/traefik/ns.yaml
  2. Create a Helm Source Custom Resource locally

    $ flux create source helm traefik \
    --url https://helm.traefik.io/traefik \
    --namespace traefik \
    --export > flux/boot/traefik/HelmRepo.yaml
  3. Create a Helm Release Custom Resource locally

    $ flux create hr traefik \
    --interval=1m \
    --source HelmRepository/traefik \
    --chart traefik \
    --chart-version 9.18.2 \
    --namespace traefik \
    --export > flux/boot/traefik/HelmRelease.yaml
  4. File structure

    $ tree
    .
    ├── README.md
    └── flux
        └── boot
            ├── flux-system
            │   ├── gotk-components.yaml
            │   ├── gotk-sync.yaml
            │   └── kustomization.yaml
            └── traefik
                ├── HelmRelease.yaml
                ├── HelmRepo.yaml
                └── ns.yaml
  5. From this point on, you are doing GitOps by interacting with your Desired State source:

    $ git add flux/boot/traefik
    $ git commit -m "Add traefik ingress controller"
    $ git push

Add Cert Manager and app without flux commands

  1. Copy traefik namespace dir we already made:

    $ cp -r flux/boot/traefik flux/boot/cert-manager
  2. File structure

    $ tree
    .
    ├── README.md
    └── flux
        └── boot
            ├── cert-manager
            │   ├── HelmRelease.yaml
            │   ├── HelmRepo.yaml
            │   └── ns.yaml
            ├── flux-system
            │   ├── gotk-components.yaml
            │   ├── gotk-sync.yaml
            │   └── kustomization.yaml
            └── traefik
                ├── HelmRelease.yaml
                ├── HelmRepo.yaml
                └── ns.yaml
  3. Manually edit files

  4. Git add, push, and show it automatically work

Repeat for example app

  1. Podinfo

    1. File structure
    $ tree
    .
    ├── README.md
    └── flux
        └── boot
            ├── cert-manager
            │   ├── HelmRelease.yaml
            │   ├── HelmRepo.yaml
            │   └── ns.yaml
            ├── flux-system
            │   ├── gotk-components.yaml
            │   ├── gotk-sync.yaml
            │   └── kustomization.yaml
            ├── podinfo
            │   ├── HelmRelease.yaml
            │   ├── HelmRepo.yaml
            │   └── ns.yaml
            └── traefik
                ├── HelmRelease.yaml
                ├── HelmRepo.yaml
                └── ns.yaml

Cleanup

  1. Delete local cluster

    $ kind delete cluster
  2. Delete demo repo & PAT from GitHub

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