Learn KOP - Part 7 - GitOps Pipelines - Rafay Product Documentation

Part 7: GitOps Pipelines

This is Part 7 of a multi-part, self-paced exercise.

What Will You Do

In this part, you will create a GitOps Pipeline to manage the lifecycle of an application. For simplicity, this part assumes the user has an account on Github and will fork the repository as a Public repository.

Estimated Time

Estimated time burden for this part is 15 minutes.

Step 1: Fork Repository

To setup a GitOps pipeline, you will need a Git repository. To help you get started, let us fork an existing repository.

This will create a copy of the repository in your Git system (e.g. GitHub). An example is shown below.

Step 2: Add Repository

Note

It does not matter if your Github repo is public or private. If private, you need to provide access credentials.

Optionally,

Step 3: Create Namespace

We need to create a namespace to deploy our workload via the GitOps pipeline

In the example below, we have created a namespace called "first" on our cluster.

Step 4: Create Workload

Now, we are ready to create a workload based on k8s manifests in our Git repository and publish it to the namespace we just created.

Step 5: Publish Workload

We are now ready to configure our workload by (a) specifying the Git repo and (b) selecting the cluster for placement.

In a few seconds, the workload's k8s resource will become operational on your cluster.

Optionally, you can also verify the status of the resources using the zero trust kubectl channel. You should see something like the following

kubectl get po -n first

NAME                                   READY   STATUS    RESTARTS   AGE
test-helm-webserver-7874b96c7c-tzpqt   2/2     Running   0          10s

Step 6: GitOps Pipeline

In the previous step, we manually created a workload and deployed it to your cluster. Every time you make a change to the manifests in your Git repo, you have to remember to republish the workload. With a GitOps pipeline, you can completely automate this ensuring that the workload on the clusters are "always kept reconciled" with changes made in the Git repository.

Add Stage

A pipeline can have multiple stages, with completely different actions to model your desired workflows. In this exercise, we will test with a single stage pipeline.

Add Trigger

A pipeline can be executed based on an "external trigger". In this exercise, we will configure a cron job based trigger that will periodically check your Git repository for modifications to the specified files.

Activate Pipeline

By default, newly created pipelines start life in a deactivated state.

Step 7: Update Git Repo

Now, you are ready to make changes in your Git repo and have the changes be picked up by the pipeline and reconciled to the clusters.

In a few seconds, the cron job based trigger will detect the changes and execute a pipeline job. In the example below, the pipeline took 22 seconds to reconcile the changes in the Git repository with the downstream clusters.

Step 8: Verify Updates on Cluster

In the example below, notice that the age of one of the pods is just 15 seconds. This was the additional replica added as part of the changes in the Git repo.

kubectl get po -n first

NAME                                   READY   STATUS    RESTARTS   AGE
test-helm-webserver-7874b96c7c-gslv4   2/2     Running   0          15s

test-helm-webserver-7874b96c7c-tzpqt   2/2     Running   0          142m

Recap

Congratulations! At this point, you have successfully created a workload and wrapped it with a GitOps pipeline for completely automated, hands off deployments.