Skip to content

Instantly share code, notes, and snippets.



Last active Oct 26, 2020
What would you like to do?
Automating Kubernetes with GitOps Workshop

Automating Kubernetes with GitOps Workshop

@dictcp (

About the workshop

Session at HKOSCon 2020:

Video recording:



Hands-on Preparation

You need

  • a GitHub account (to access this material and setup gitops flow)
  • a working Kubernetes in the hands-on session (to s)

multipass VM

  1. Install multipass on
    • support Windows 10 Pro+, Mac OS X, Linux
    • Mac OS X (with homebrew installed): brew cask install multipass
    • Ubuntu (or any Linux distro with snap installed): sudo snap install multipass --classic
  2. Start Command prompt / Terminal
  3. Execute multipass launch -d 30G -m 2G --name fluxcd-workshop 18.04
  4. Depends on network condition, you need to wait for 5-20 mins.
  5. Check the IP of your VM via command multipass info fluxcd-workshop
Name:           fluxcd-workshop
State:          Running
Release:        Ubuntu 18.04.4 LTS
Image hash:     55646c02a8bc (Ubuntu 18.04 LTS)
Load:           1.46 5.28 3.97
Disk usage:     4.5G out of 28.9G
Memory usage:   1.5G out of 1.9G
  1. Execute multipass shell fluxcd-workshop to obtain shell in the VMs

DigitalOcean VM

  1. (If need) Signup DigitalOcean via
  2. create a droplet with 2GB and Ubuntu 18.04
  3. Wait a few minutes, and you can connect to the ssh root@<<YOUR_DROPLET_IP>>

Install k3s Kubernetes on your VM

  1. Connect to the shell of the VM set up
  2. Execute curl -sfL | sh - in the VM
  3. Depends on network condition, you need to wait for 5-10 mins.
  4. You should have your local Kubernetes cluster installed. To verify, execute sudo -i k3s kubectl get nodes, it should give you something like
NAME              STATUS   ROLES    AGE     VERSION
fluxcd-workshop   Ready    master   5m53s   v1.18.3+k3s1`
  1. Make sure the cluster setup is avaiable by the following commands:
$ mkdir .kube
$ sudo cat /etc/rancher/k3s/k3s.yaml > .kube/config

Install Helm & fluxctl

Normally you can install helm and fluxctl with the following 4 commands:

sudo snap install kubectl --classic
sudo snap install helm --classic --channel=3.0/stable
sudo snap install fluxctl --classic
sudo rm /usr/local/bin/kubectl

Manual steps (if the above does not work)

  • Helm
$ curl -fsSL -o
$ chmod 700
$ ./
$ helm version
version.BuildInfo{Version:"v3.2.3", GitCommit:"8f832046e258e2cb800894579b1b3b50c2d83492", GitTreeState:"clean", GoVersion:"go1.13.12"}
  • fluxctl
wget -O fluxctl
chmod +x fluxctl
sudo mv fluxctl /usr/local/bin/

Prepare the git repository for GitOps

  1. Fork in GitHub to your own account

Install fluxcd

  1. Setup the chart repository for flux
helm repo add fluxcd
  1. Install flux on Kubernetes cluster via Helm, with following commands
$ export GHUSER="dictcp"

$ kubectl create ns flux
$ helm upgrade -i flux fluxcd/flux \
  --set${GHUSER}/flux-get-started \
  --set 'git.path=namespaces\,workloads' \
  --namespace flux
  1. Copy the public SSH key
fluxctl identity --k8s-fwd-ns flux
  1. Setup the in GitHub (eg.${GHUSER}/flux-get-started/settings/keys) Remember to enable Allow write access

  2. Trigger sync

fluxctl sync --k8s-fwd-ns flux
  1. View the applied change (you should see a demo namespace
kubectl get ns

fluxcd playaround

  1. copy manifests-sample/podinfo-dep.yaml and manifests-sample/podinfo-svc.yaml to workloads/ in your flux-get-started repos; commit change and push

  2. check deployment progress watch kubectl -n demo get pod

Install Helm operator

  1. Install the CRD for HelmRelease
kubectl apply -f
  1. Install Helm Operator via Helm
helm upgrade -i helm-operator fluxcd/helm-operator \
--set git.ssh.secretName=flux-git-deploy \
--set helm.versions=v3 \
--namespace flux

Helm operator playaround

  1. copy releases/ghost.yaml as workloads/ghost.yaml in your flux-get-started repos; commit change and push OR running command
cat <<EOF | kubectl apply -f -
kind: HelmRelease
  name: ghost
  namespace: demo
  annotations: "false" glob:3.1.1-debian-9-*
  releaseName: ghost
    git: ssh://
    ref: master
    path: charts/ghost
      repository: bitnami/ghost
      tag: 3.1.1-debian-9-r0
      enabled: false
        memory: 32Mi
        cpu: 10m
      type: ClusterIP
          enabled: false
  1. check Helm install progress watch kubectl -n demo get hr

  2. Port-forward the result kubectl -n demo port-forward --address service/ghost 8080:80

  3. Open browser and check the result

Set up Lens

  1. install Lens at

    • Mac OS X (with homebrew installed): brew cask install lens
  2. Add clusters with your KUBECONFIG

  3. check it out

Continuous Delivery

  1. Check into the magic of annotations "true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment