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
metadata:
  labels:
    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
metadata:
  name: nginx-deployment
  namespace: laflux
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - 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 
--git-user=${GLUSER} 
--git-email=${GLUSER}@gmail.com 
--git-url=git@gitlab.com:${GLUSER}/flux-sample 
--git-path=namespaces,workloads 
--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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?