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 ACloudGuru-Resources/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 thehello.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: acgtes/gitops:hellov1.1
- Create Another hello.yaml in a Folder Called production
Create a folder called
production
with the samehello.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: acgtes/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 theworkloads
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 theproduction
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.