Infrastructure Management - fluxcd/flux2-kustomize-helm-example

In this guide, we will go through the process of installing and configuring essential infrastructure components using Helm charts and Kustomize, with a focus on the project fluxcd/flux2-kustomize-helm-example.

Prerequisites

  • Kubernetes cluster
  • Helm v3 installed
  • kubectl configured to interact with the cluster

Flux

Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration. It can be installed using the official Helm chart.

Install Flux

  1. Add the Flux Helm repository:
helm repo add fluxcd https://charts.fluxcd.io
  1. Install the Flux Helm chart:
helm install flux fluxcd/flux --namespace flux-system

Flux Components

Flux consists of several components:

  • Source Controller: Acquires Helm charts from Helm repositories or other sources.
  • Helm Controller: Manages Helm artifacts.
  • Kustomize Controller: Reconciles the cluster state with the desired state as defined by Commit manifests retrieved through Source controller.

Helm

Helm is a package manager for Kubernetes that allows you to package your Kubernetes deployments into reusable components, called charts.

Helm Repository

A Helm repository is a web server that houses packaged Helm charts. You can host your own Helm repository or use an existing one.

Add a Helm Repository

To add a Helm repository, use the helm repo add command. For example, to add the Bitnami Helm repository:

helm repo add bitnami https://charts.bitnami.com/bitnami

Install a Chart from a Helm Repository

To install a chart from a Helm repository, use the helm install command. For example, to install the Contour chart from the Bitnami Helm repository:

helm install contour bitnami/contour

HelmRelease

A HelmRelease is a Kubernetes custom resource that manages the release of a Helm chart in a cluster.

Create a HelmRelease

To create a HelmRelease, use the kubectl apply command. For example, to create a HelmRelease for the Contour chart:

apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: contour
namespace: ingress-nginx
spec:
chart:
spec:
chart: contour
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
version: ~1.21.0
releaseName: contour

Kustomize

Kustomize is a standalone tool to customize Kubernetes objects through a kustomization file.

Kustomization

A kustomization file is a YAML file that defines a set of customizations to apply to a set of Kubernetes objects.

Create a Kustomization

To create a kustomization file, create a kustomization.yaml file in a directory. For example:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml
- service.yaml

patchesStrategicMerge:
- patch.yaml

Apply a Kustomization

To apply a kustomization, use the kubectl apply command. For example:

kubectl apply -k .

GitOps

GitOps is a way of doing Kubernetes cluster management by using Git as the source of truth.

Flux GitOps

Flux supports GitOps through its Source Controller and Kustomize Controller.

Configure Flux GitOps

To configure Flux GitOps, create a GitRepository custom resource. For example:

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: my-repo
namespace: flux-system
spec:
url: https://github.com/my-user/my-repo.git
ref: main

Cert-Manager

Cert-Manager is a Kubernetes add-on to automate the management and issuance of TLS certificates from various issuers.

Install Cert-Manager

To install Cert-Manager, use the official Helm chart.

  1. Add the Cert-Manager Helm repository:
helm repo add jetstack https://charts.jetstack.io
  1. Install the Cert-Manager Helm chart:
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace

Ingress-NGINX

Ingress-NGINX is a Kubernetes ingress controller that manages external access to the services in a cluster.

Install Ingress-NGINX

To install Ingress-NGINX, use the official Helm chart.

  1. Add the Ingress-NGINX Helm repository:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
  1. Install the Ingress-NGINX Helm chart:
helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx

Conclusion

In this guide, we have gone through the process of installing and configuring essential infrastructure components using Helm charts and Kustomize. We have covered the following topics:

  • Flux
  • Helm
  • Kustomize
  • GitOps
  • Cert-Manager
  • Ingress-NGINX

You can use this guide as a reference for installing and configuring these components in your own Kubernetes cluster.