GitOps with Flux and Kustomize

  1. You will need to select a GitHub repository of an application or service you want to sync. You will need access to save a deploy key in GitHub for that repo. My repo as an example: https://github.com/airwavetechio/hello-world
  2. We are going to install & deploy Flux into a minikube cluster. This will point to your GitHub repository. You should have minikube up and running before starting this exercise.
  3. Solidify the connection from Flux to the repository by adding a deploy key that is created after you install flux in your cluster.
  4. Sync your repo with your cluster and watch Kustomize take care of applying those changes.

2. Install & Deploy Flux

We are going to skip step 1 and jump right into step 2.

fluxctl install --manifest-generation=true --git-user=<a git user> --git-email=<email used for git> --git-url=git@github.com:org/<repo> --git-branch <branch> --git-path=<path to your files, additional path> --namespace=<namespace> | kubectl apply -f -
fluxctl output
kubectl get pods -n flux

An explanation of git-path

--git-path=flux/releases/namespaces,flux/releases/airwave-stage

directory structure
.flux.yaml

flux\releases\namespaces

I have added namespaces as an example of how to setup namespace the #GitOps way.

namespace\kustomization.yaml
namespaces\airwave-stage.yaml

flux\releases\base\

base contains all the base files. In this case, our deployment, service, and configmap YAML files. The files mentioned below can be found in our hello-word repo.

base\kustomization.yaml
excerpt of base\deployment.yaml
base\service.yaml
base\configmap.yaml

flux\releases\airwave-stage

In this use case, we want to deploy hello-world to the airwave-stagenamespace.

a visual assistant
airwave-stage\kustomization.yaml
airwave-stage\configmap.yaml
airwave-stage\service.yaml

3. Solidify the connection from Flux to the repository by adding a deploy key

fluxctl identity --k8s-fwd-ns flux will output an ssh public key that is generated by the Kubernetes cluster. The cluster itself has the private key.

Allow write access

4. Sync your repo with your cluster

fluxctl --k8s-fwd-ns flux sync to kick off the process. You can also wait for 5 minutes.

the git commit hash should match your latest commit in GitHub
The state of things
kubectl get pods -n airwave-stage
kubectl describe configmap hello-world-configmap -n airwave-stage
kubectl describe service airwavetech-helloworld-svc -n airwave-stage

Conclusion

In this exercise, we have taken our hello-world service, configured flux and Kustomize in our minikube cluster to sync with our GitHub repo, and have watched an automated deployment of that service to a specific namespace with a specific configuration. Welcome to the future. “This is heavy.”

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store