Skip to content

Instantly share code, notes, and snippets.

@priyanka-ravi
Last active November 5, 2022 02:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priyanka-ravi/1edc892266c70efd17ba3b4d9e76a6bc to your computer and use it in GitHub Desktop.
Save priyanka-ravi/1edc892266c70efd17ba3b4d9e76a6bc to your computer and use it in GitHub Desktop.

This demo will walk you through how to stand up a kind cluster and bootstrap Flux into it and deploy an application using Flux.

Pre-requisites

A basic understanding of Git and Docker/containers, A GitHub account, Docker Desktop installed, KIND installed, kubectl installed, and Flux CLI installed

Set up local cluster and Flux CLI

  1. Install Flux CLI and Kind (If not using a mac you can find installation instructions on both project's getting started guides)

    $ brew install fluxcd/tap/flux
    $ brew install kind
  2. Create local demo cluster

    $ kind create cluster --name flux
    (took 37s)

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
    $ export GITHUB_OWNER=<your GitHub>

Bootstrap Flux both for your source and in cluster

  1. Simple bootstrap:

    $ flux bootstrap github \
    --owner $GITHUB_OWNER \
    --personal \
    --private \
    --repository flux-demo \
    --path=clusters/my-cluster
    ► connecting to github.com
    ✔ repository "https://github.com/priyanka-ravi/flux-demo" created
    ► cloning branch "main" from Git repository "https://github.com/priyanka-ravi/flux-demo.git"
    ✔ cloned repository
    ► generating component manifests
    ✔ generated component manifests
    ✔ committed sync manifests to "main" ("8122eb8f6cd0c520a757aafde01462946e2b07e8")
    ► pushing component manifests to "https://github.com/priyanka-ravi/flux-demo.git"
    ► installing components in "flux-system" namespace
    ✔ installed components
    ✔ reconciled components
    ► determining if source secret "flux-system/flux-system" exists
    ► generating source secret
    ✔ public key: ssh-rsa ****
    ✔ configured deploy key "flux-system-main-flux-system-./clusters" for "https://github.com/priyanka-ravi/flux-demo"
    ► applying source secret "flux-system/flux-system"
    ✔ reconciled source secret
    ► generating sync manifests
    ✔ generated sync manifests
    ✔ committed sync manifests to "main" ("06360186166df1ebbba33b5be07bea60b77e39f1")
    ► pushing sync manifests to "https://github.com/priyanka-ravi/flux-demo.git"
    ► applying sync manifests
    ✔ reconciled sync configuration
    ◎ waiting for Kustomization "flux-system/flux-system" to be reconciled
    ✔ Kustomization reconciled successfully
    ► confirming components are healthy
    ✔ source-controller: deployment ready
    ✔ kustomize-controller: deployment ready
    ✔ helm-controller: deployment ready
    ✔ notification-controller: deployment ready
    ✔ all components are healthy
    (took 1m12s)

Clone the flux-demo repo and create new tenant (namespace)

  1. Clone the newly created git repo to your local workspace

    $ git clone git@github.com:$GITHUB_OWNER/flux-demo.git
    $ cd flux-demo
  2. Make directory for the new tenant files and export create tenant

    $ mkdir -p ./clusters/my-cluster/test
    $ flux create tenant test --with-namespace=test --export >> ./clusters/my-cluster/test/rbac.yaml
    $ cat ./clusters/my-cluster/test/rbac.yaml
  3. Fork podinfo-deploy repo - how to fork a repo

    https://github.com/priyanka-ravi/podinfo-deploy

  4. Create source and kustomization into sync.yaml file

    $ flux create source git podinfo \
      --namespace=test \
      --url=https://github.com/$GITHUB_OWNER/podinfo-deploy \
      --branch=main \
      --export > ./clusters/my-cluster/test/sync.yaml
      
    $ flux create kustomization podinfo \
      --namespace=test \
      --source=GitRepository/podinfo \
      --path="./" \
      --export >> ./clusters/my-cluster/test/sync.yaml
      
    $ cat ./clusters/my-cluster/test/sync.yaml
    $ git add .
    $ git commit -m "Add test namespace podinfo sync.yaml"
    $ git push
    $ flux reconcile ks flux-system --with-source
    $ flux get source git -A
    $ flux get ks -A
  5. Port forward the podinfo application to access it

    $ kubectl port-forward service/frontend 9898:9898 --namespace test

    http://localhost:9898/

  6. Change in frontend/deployment.yaml the UI color to 888888

    env:
        - name: PODINFO_UI_COLOR
          value: "#888888"
    $ flux reconcile -n test ks podinfo --with-source

    NOTE: You may have to kill and restart the previous port-forward command.

Delete pod and see Flux stand it back up to show configuration drift management

$ kubectl delete deployment/frontend -n test
$ kubectl get pods -n test -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment