GitOps with flux2

Yashwanth Lakkaraju
3 min readJun 11, 2022

--

What? Why? How?

flux2 is one of the tool among various others like argo-cd, that has taken the pace in the GitOps model of releasing your software, post the initial version flux — which has fallen into maintenance mode. flux2 is a model where deployments are handled as Code and changes are processed when changes are done in the Source Control. The great thing about the tool is that you do not need anything with kubectl or helm but goes through the same process as the source code and off-course it is persisted in git.

The Basics

Sources

It is the origin of a repository contains all the requirements to be available in the repository which is checked at regular intervals and makes sure the git state state matches the cluster. Examples of sources are:

  • GitRepository
  • HelmRepository
  • Bucket

Reconcile

This is matching the given state to desired state, matching to the sources defined above. In flux ecosystem there are as below:

  • HelmRelease Reconciliation — Ensures the state of the HelmRelease(HR) matches what is defined.
  • Kustomization Reconciliation — Ensures the state of the application on the cluster matches that is(are) defined in a sources listed above.

The Components

Source Controller

It is a Kubernetes Operator, to fetch data from external Sources.

Kustomize Controller

It is a Kubernetes Operator, specialised in running CD(Continuous Delivery) for workloads defined with k8s manifests and merged with Kustomize.

Helm Controller

It is a Kubernetes Operator, which and where Helm Chart releases are declaratively declared to generate Kubernetes manifests.

Helm release is described through a Kubernetes Custom Resource Definition(CRD) called asHelmRelease. Based on the activity of this CRD, actions are performed by this controller.

Source: https://github.com/fluxcd/flux2/raw/main/docs/_files/gitops-toolkit.png

Notification Controller

It is a Kubernetes Operator, which handles all events from sources and sends them over to external “notification” systems.

Image Automation Controller

This has 2 internal components, namely image-reflector-controller and image-automation-controller

It is a Kubernetes Operator, which checks for any new images from the asImageRepository and updates cluster. Also this change is reflected in the Source with ImageUpdateAutomation

Hands-on

Now, lets get some hands dirty with this..

Install on the Cluster

Option-1: Manual

The steps to install are explained over the flux2 documentation page.

Option-1: Infrastructure As Code

Since I prefer terraform as the go-to tool for infrastructure as code, a provider is already available HERE.

Also, I am working to add a terraform module under at tf-k8s-fluxv2

Install CLI

Run the below command:

curl -s https://raw.githubusercontent.com/fluxcd/flux2/main/install/flux.sh | sudo bash

Commands

Shell Alias’s

export FLUX_NAMESPACE="flux-system"
alias fghr="flux get hr"
alias fgks="flux get ks"
alias fgs="flux get sources"
alias fgsg="flux get sources git"
alias fgsh="flux get sources helm"
alias fgir="flux get image repository"
alias fgip="flux get image policy"
alias fgiu="flux get image update"
alias frks="flux reconcile ks"
alias frhr="flux reconcile hr --with-source"
alias frs="flux reconcile source"
alias frsg="flux reconcile source git"
alias frsh="flux reconcile source helm"
alias frir="flux reconcile image repository"
alias friu="flux reconcile image update"
alias frmks="flux delete ks"
alias frmhr="flux delete --silent hr"
alias frms="flux delete source"
alias frmsg="flux delete source git"
alias frmsh="flux delete source helm"
alias fbk="flux build kustomization"
alias fdk="flux diff kustomization"
alias floh="kubectl -n ${FLUX_NAMESPACE} logs deployment/helm-controller -f --tail=100"
alias flloha="kubectl -n ${FLUX_NAMESPACE} logs deployment/helm-controller -f"
alias flos="kubectl -n ${FLUX_NAMESPACE} logs deployment/source-controller -f --tail=100"
alias flosa="kubectl -n ${FLUX_NAMESPACE} logs deployment/source-controller -f"

--

--

Yashwanth Lakkaraju
Yashwanth Lakkaraju

Written by Yashwanth Lakkaraju

📌 🇩🇪 • 🇮🇳 ➡️ 🇺🇲 ➡️ 🇩🇪 | Learner | Engineer | Techie | Nethead

No responses yet