Setup a GitLab GitOps workflow for Kubernetes

Create Kubernetes cluster on node c2d-ks1 and manage it using GitLab Agent.

This how-to demonstrates how we can manage a MicroK8s Kubernetes cluster running on c2d-ks using a GitLab Agent running in the cluster. This GitLab Agent configuration and Kubernetes manifest files are in a separate project c2platform/examples/kubernetes/gitlab-gitops. Separate from the Ansible project c2platform/ansible that is used to initially create the cluster using Ansible.


Overview

This example project uses GitOps workflow to manage OpenShift resources in two namespaces nja and njp. The first namespace is for is the “acceptance” environment, the second for “production”. See manifests/staging.yml and manifests/production.yml. The diagram below only shows njp. The setup for nja and njp is identical with the exception of the fact that njp is configured to pull only images with tag production. This project uses the Docker image from project c2platform/examples/kubernetes/gitlab-docker-build.

Prerequisites

GitLab Agent

To register an GitLab Agent you will have to configure an “access token” for Ansible. In this “development” project these type of local secrets are stored using var c2_gitlab_agent_access_token in file group_vars/all/local_stuff.yml. See Local Stuff.

Create an access token see Install Gitlab Agent for more information. This how-to describes the manual install of an GitLab Agent.

For example in project c2platform/examples/kubernetes/gitlab-gitops navigate to InfrastructureKubernetes clusters, click on c2d-mk8s and then select tab Access tokens  and click Create token.

Create ( or update ) the file group_vars/all/local_stuff.yml and add

c2_gitlab_agent_access_token: <access-token-of-gitlab-project>

Create c2d-ks1

To create the Kubernetes node c2d-ks1 perform following steps:

  1. Setup Kubernetes
  2. Setup the Kubernetes Dashboard

Gitlab Agent

See Install Gitlab Agent

Verify

If the GitLab Agent for gitlab-gitops  project is successfully created, a simple application is deployed that should be accessible http://1.1.4.12:3000/  and http://1.1.4.13:3000/  . See c2platform/examples/kubernetes/gitlab-gitops for more information.

With c2d-rproxy1 running and provisioned you should be able to go to https://frontend-nja.k8s.c2platform.org/  and https://frontend-njp.k8s.c2platform.org/  and see the message

Hello World!

If you have the Kubernetes Dashboard add-on enabled you should be able to navigate to Kubernetes Dashboard  and then see for example the service frontend-service in namespace nja with external endpoint http://1.1.4.12:3000/ 

Using your browser, you can navigate to http://1.1.4.12:3000/  and see the text. Or use curl

vagrant@c2d-ks1:~$ curl http://1.1.4.12:3000/
Hello World! Version: 0.1.5vagrant@c2d-ks1:~$


Last modified November 13, 2024: translate false C2-587 (af41e45)