By Melveta Aitkinson – DevOps Engineer
This blog covers how to set up Flux for Helm and EKS.
First, let’s cover what Flux, Helm, and EKS are. An important concept here is GitOps because Flux is a tool for GitOps. By definition, GitOps is an operational framework that takes DevOps best practices used for application development such as version control, collaboration, compliance, and CI/CD, and applies them to infrastructure automation. Flux allows you to synchronize the state of manifests (YAML files) in a Git repository to what is running in a cluster. So, what does this allow you to do? It allows for the direction of push code into different environments (Dev, QA, Prod) from the version-controlled system like Git and have it automatically updated in your Kubernetes cluster. This example illustrates the use of EKS in AWS. Let’s quickly touch on Helm. Think of Helm like a package manager. It helps install and manage Kubernetes applications, which is in the form of Helm charts.
Requirements:
GIT
Helm
Flux
Git/Helm repository (in this example we will be using GitLab)
A running Kubernetes cluster and kubectl (in this example we will be using EKS in AWS)
Environment setup:
If you are following this example using EKS, please feel free to use https://keyvatech.com/2022/02/25/create-eks-clusters-in-aws-using-eksctl/ to quickly spin up a EKS cluster. Remember to shut down unused resources. This is for commands running on a Mac, some steps may differ on another OS:
LINKEDIN Environment setup:
If you are following this example using EKS, https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html. Remember to shut down unused resources. This is for commands running on a Mac, some steps may differ on another OS:
Setting up Flux
- Creating a Helm Chart
helm create <chartname>
Bootstrap Kubernetes cluster
- This installs Flux on Kubernetes cluster
- If namespace is not included, Flux will create/use a default namespace of “Flux-system”
flux bootstrap gitlab --ssh-hostname=gitlab.com --owner=<group owner of repository> --repository=<name of repository> --path=<directoy path to be synced> --branch=<repository branch> --namespace <kubernetes namespace>
Add Helm repository
- Adds GitLab repository as Helm chart repository, allowing for a centralized location to store Helm charts
helm repo add --username <gitlab username> --password <gitlab token> <repository name> <https://gitlab.com/api/v4/projects/><project id>/packages/helm/stable
Package Helm chart
- chartname is the same as the create chart command
- Command produces a file with the following format: <chartname>-0.1.0.tgz in the directory that command is executed
helm **package** <chartname>
Push Helm chart
- Helm repo is the same used in the Helm repo add command
helm cm-push <chartname>-0.1.0.tgz <helm repo>
Create a Helm source
- Creates a Helm repo from the URL provided and fetches an index
flux create source helm <name of source> --url=https://gitlab.com/api/v4/projects/<project_id>/packages/helm/stable --interval=<interval for sync> --username=<gitlab username> --password=<gitlab token> --namespace <kubernetes namespace>
Create a Helm release
- Pulls down the chart, deploys resources and syncs with the cluster
flux create helmrelease <name of helmrelease> --chart=<chartname> --source=HelmRepository/<repo name> --chart-version="<chart-version>" --namespace <kubernetes namespace>
Confirm Helm release and charts with the following commands:
kubectl get hr -A
helm list -A