Deploying Applications with GitHub Actions Workflow and Flux

45 minutes
  • 8 Learning Objectives

About this Hands-on Lab

This hands-on lab challenges the student to implement Flux within a GitHub environment, taking into account the need to deploy applications into development, test, and production environments. This lab challenges the student to set up Kubernetes YAML to deploy workloads into a QA and Production Cluster.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Fork or Create a GitHub Repository

Please set up a repository for this lab. If you have one from a prior lab, it should work for you. If not, you may fork the linuxacademy/content-gitops repository.

Create the Hello YAML in a Folder Called qa

If the folder qa does not exist in the repository, create that folder and create the hello.yaml file within it.

The content of the yaml file is:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  namespace: lasample
  labels:
    app: hello
spec:
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: linuxacademycontent/gitops:hellov1.1
Create Another hello.yaml in a Folder Called production

Create a folder called production with the same hello.yaml file in it.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  namespace: lasample
  labels:
    app: hello
spec:
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello
        image: linuxacademycontent/gitops:hellov1.1
Deploy the Flux Daemon and Configure It To Scan the qa Folder

Deploy Flux as in other labs with the following commands:

Install the fluxctl software:

$ sudo snap install fluxctl --classic

Create the flux namespace:

$ kubectl create namespace flux

Set the GHUSER Environment variable to your GitHub username:

$ export GHUSER=[Your username here]

Deploy Flux, but notice that we are scanning the qa folder not the workloads folder:

$ fluxctl install 
--git-user=${GHUSER} 
--git-email=${GHUSER}@users.noreply.github.com 
--git-url=git@github.com:${GHUSER}/content-gitops 
--git-path=namespaces,qa 
--namespace=flux | kubectl apply -f -

Set the environment variable for the fluxctl command:

$ export FLUX_FORWARD_NAMESPACE=flux

Grab the RSA key created by Flux:

$ fluxctl identity

The alternative is to not set the FLUX_FORWARD_NAMESPACE variable and instead use this command:

$ fluxctl identity --k8s-fwd-ns flux

Copy and past that RSA key into the Deploy Keys within your GitHub Repo.

Add the Deploy Key to Your Repo

Use the RSA key copied to the clipboard to add a "Deploy Key" in GitHub, or an SSH RSA Key in other Git servers, to grant read and write access to your QA Kubernetes Cluster.

Use the list-workloads Command To Examine The Deployed Container Images

If you have not set the FLUX_FORWARD_NAMESPACE variable, you should do so now:

$ export FLUX_FORWARD_NAMESPACE=flux

Use fluxctl to examine the container images deployed:

$ fluxctl list-workloads --all-namespaces
Change the hello.yaml File in the QA Folder to Deploy Version 1.2

Change the hello.yaml file to deploy the version 1.2 of the container image.

Then sync with:

$ fluxctl sync

Check the container running with:

$ fluxctl list-workloads --all-namespaces
Delete the flux and lasample Namespaces and Repeat the Install for Production

Delete the running instance of Flux on your cluster:

$ kubectl delete namespace flux

Delete the deployed hello workload:

$ kubectl delete namespace lasample

Then repeat the steps to install the flux daemon, but this time configure for scanning the production folder:

$ fluxctl install 
--git-user=${GHUSER} 
--git-email=${GHUSER}@users.noreply.github.com 
--git-url=git@github.com:${GHUSER}/content-gitops 
--git-path=namespaces,production 
--namespace=flux | kubectl apply -f -

Then test by changing the hello.yaml file in the production folder to deploy other images.

Additional Resources

To complete this lab the student must have their own GitHub or GitLab account and be able to set up a repository with the required YAML files. The student should also be familiar with the installation and configuration of Flux, which is covered in a prior lab as part of the GitOps course.

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!

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