Installing and Configuring Flux with GitLab

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

This lab is provided for students that do not utilize GitHub and prefer to use GitLab or some other VCS repository manager with Flux. This lab covers the installation of Flux when a student is using a repository on GitLab.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set Up A Repository (Project) In GitLab

The student must have a GitLab account, and set up a repository within that account. The repository should contain two files that are Kubernetes YAML. The first, within the namespaces folder, will create a namespace for the application. The YAML is as follows:

apiVersion: v1
kind: Namespace
    name: laflux
  name: laflux

The second file is for creating the actual deployment of an NGINX server. The YAML should be in the workloads folder. That YAML is as follows:

apiVersion: apps/v1
kind: Deployment
  name: nginx-deployment
  namespace: laflux
    app: nginx
  replicas: 2
      app: nginx
        app: nginx
      - name: nginx
        image: nginx:1.7.9
        - containerPort: 80
Establish a Terminal Session on the Kubernetes Master and Install Flux

Use SSH to establish a session on the Kubernetes host server:

ssh cloud_user@[IP Address Here]

Use the password supplied in the lab interface.

To verify that fluxctl was installed automatically, type:

$ fluxctl version

If it was not installed automatically, you may enter:

$ sudo snap install fluxctl --classic

Once on the server, create the namespace to run Flux:

$ kubectl create namespace flux

Then set the GLUSER environment variable:

$ export GLUSER=[your GitLab username]

Then input the command to run flux:

$ fluxctl install 
--namespace=flux | kubectl apply -f -

You may check the deployment with the following command:

$ kubectl -n flux rollout status deployment/flux
Obtain the RSA Key Created by fluxctl, and Grant GitLab Write Permission to the Cluster

Obtain the RSA key created by the Flux install procedure with the following command:

$ fluxctl identity –k8s-fwd-ns flux

Then copy the RSA key to the clipboard and use the Settings->SSH Keys feature in GitLab to add the SSH Key.

Use the fluxctl sync Command to Synchronize the Cluster

After the GitLab account has been granted write access to the Cluster, use the sync command to apply the YAML from the repository:

$ fluxctl sync –k8s-fwd-ns flux

Once the sync command has run, you may check that the namespace has been created and that the NGINX deployment has been applied and deployed:

$ kubectl get pods –all-namespaces

Additional Resources

To perform this lab the student must have their own GitLab account and be able to set up a repository in that system to use with Flux.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?