Flux CD

Installing and configuring Flux CD locally allows you to test and develop GitOps-related features and integrations.

Install dependencies

You need to be able to access a Kubernetes cluster locally using the kubectl command.

If you want to host a local Kubernetes cluster for development purposes, you can use Rancher Desktop or k3d.

Create a personal access token

To authenticate with the Flux CLI, create a personal access token with the api scope:

  1. On the left sidebar, select your avatar.
  2. Select Edit profile.
  3. On the left sidebar, select Personal access tokens.
  4. Enter a name and optional expiry date for the token.
  5. Select the api scope.
  6. Select Create personal access token.

Create a SSH key

Generate an SSH key for GDK access:

  1. Run the command:

    ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/gdk
  2. Copy the generated public key:

    cat ~/.ssh/gdk.pub | pbcopy
  3. Register it for your user:

    1. On the left sidebar, select your avatar.
    2. Select Edit profile.
    3. On the left sidebar, select SSH Keys > Add new key.
    4. Add the copied public key.

Create a project in your GDK

Create a project to hold the Flux configuration. It can be an empty project within any group. For example, you can create a project named flux-config in the gitlab-org group.

Complete a bootstrap installation

Bootstrap Flux into an empty GitLab repository with the flux bootstrap command.

Since you only need Flux for development purposes, you can use an SSH repository connection. This simplifies the local GDK setup, including avoiding an issue where Flux doesn’t verify local certificates if GDK runs behind NGINX.

To bootstrap flux, run this command:

flux bootstrap git \  --url=<ssh link to git repository> \  --branch=main \  --private-key-file=<path to ssh key file> \  --path=clusters/my-cluster

If using the example values from previous steps, your command should look like this:

 flux bootstrap git  --url=ssh://git@gdk.test:2222/gitlab-org/flux-config.git \  --branch=main \  --private-key-file=/Users/username/.ssh/gdk \  --path=clusters/test-cluster

Set up the KAS integration

To fully replicate a GitOps configuration locally, you’ll also need to create and register an agentk.

First, make sure your GDK is properly set up for KAS.

Then follow the Flux set up tutorial with the following modification: When installing the agentk with Flux, use the grpc address to connect to KAS. If you used the default loopback alias IP your YAML configuration should look like:

--- apiVersion: source.toolkit.fluxcd.io/v1beta2 kind: HelmRepository metadata:  labels:  app.kubernetes.io/component: agentk  app.kubernetes.io/created-by: gitlab  app.kubernetes.io/name: agentk  app.kubernetes.io/part-of: gitlab  name: gitlab-agent  namespace: gitlab spec:  interval: 1h0m0s  url: https://charts.gitlab.io --- apiVersion: helm.toolkit.fluxcd.io/v2beta1 kind: HelmRelease metadata:  name: gitlab-agent  namespace: gitlab spec:  chart:  spec:  chart: gitlab-agent  sourceRef:  kind: HelmRepository  name: gitlab-agent  namespace: gitlab  interval: 1h0m0s  values:  config:  kasAddress: "grpc://172.16.123.1:8150"  secretName: gitlab-agent-token

Once the agent is installed, you’ll have a fully functional local GitOps solution you can use for development purposes.

Last updated on