DevOps Tools Integration on Jelastic – GitLab & Kubernetes K8s

  • October 20, 2021
  • 53 Views

In order to create a CI/CD pipeline using Gitlab and Kubernetes, Jelastic Paas provides its users with a built-in solution to easily connect both tools together.
On this article we’ll provide you with a guided explanation to install both environments, connect them and try a simple CI/CD implementation provided by Jelastic team.
First, you should start by installing both Kubernetes and GitLab into your Jelastic environment. To install them, click on the marketplace button.

Both the Kubernetes Cluster and the DevOps Lab GitLab Server are on the cluster section of the Marketplace :

By hovering over Kubernetes, a small window with details and an install button will be presented :

By clicking on the install button, a window pops up for you to set Kubernetes’ cluster configurations.

Set the kubernetes’ cluster environment name and check the “Remote API Access” module’s box then click install. Now wait for the installation process that might take up to few minutes. Once installation is completed, a window with the required credentials is presented.
NB : Please do save your credentials somewhere, you’ll need them later on.

Now that Kubernetes cluster is installed, let’s install the GitLab Server. Hover over “DevOps Lab – GitLab Server” on the cluster section of the Marketplace and click install. Once the configurations’ window pops up, set the environment name then click the install button.

Once the installation is finished, you’ll be presented by Gitlab’s login credentials :

Now that both environments are installed, let’s configure the GitLab-Kubernetes integration. On the Kubernetes cluster, head to the control panel section and click the “Adds-on” icon:

Now that Kubernetes cluster’s Adds-on window is opened, click the configure button of the “GitLab Integration” module.

Choose the GitLab Server that you’d like to integrate, from the presented list of the installed tools you have in your environment.

Once you chose the server, click on the “Apply” button and wait for the integration to be set.

Now that you set both environments as well as Gitlab – Kubernetes integration, let’s sign in to the GitLab platform using credentials provided by the Jelastic platform back when you created your Gitlab Server instance.
NB: Make sure that your GitLab Server is on “Running” Mode.

After signing in to your Gitlab account, you’ll now add your project by clicking the “New Project” button.

In this tutorial, we will import a project from an existing Github Repository, therefore you’ll need to follow the steps below :

  1. Click on the “Import Project” button

2. Choose GitHub

3. By choosing to import a project from Github, you need to define a “Personal Access Token” to authenticate to Github.

To obtain a Personal Access Token, head over to your GitHub Account. Go to Settings Section.

Now select “Developer Settings”

Then go to the “Personal Access Token” section and click on “Generate Token”.

You could add a note to your token and change its “Expiration” delay, and you should at least check the “repo” checkbox to give permissions to GitLab to import code from your Github repository.

Finally, click the “Generate Token” button.

NB : Please copy your generated token and save it somewhere, you won’t be able to find it again in “Personal Access Token” section the next time you need it.

Now that you have a personal access token paste it on the Gitlab platform to authenticate with Github and then click on the “Authenticate” button.

Now you have all of you Github repositories listed, choose the one you would like to import, and click the “import” button. Wait few minutes.

Once the project is imported, you’ll get the “complete” status and you could go to your project by clicking the “Go to Project” button.

Nb: Please check that all your files have been imported.
Now in order to run your GitLab CI/CD pipeline you’ll need to set some variables. For that go to the CI/CD section under the settings section.

Once you access the CI/CD section expand the “Variables” section.

Now click the “Add variable” button to start adding variables.

Here’s the list of variables that you should be having by the end.

CI_REGISTRY_USER and CI_REGISTRY_PASSWORD are your DockerHub credentials.

K8S_CA_B64 must contain a certificate required by the Kubernetes authorization module. To obtain a certificate, run the command below on the control plane node of your Kubernetes cluster on the p4d platform and take the value from the keypair.

Command : kubectl config view –raw -o json | grep certificate-authority-data

K8S_SERVER contains a Kubernetes control plane node URL. You could get it by running the command below :

kubectl cluster-info | grep ‘Kubernetes control plane’ | awk ‘/http/ {print $NF}’

K8S_TOKEN is the token that you had when you installed the Kubernetes Cluster.

NB : Since this tutorial is based on Jelastic teams’ Github project linked below, those are the variables that we’ll need for our topology and to be able to run our CI/CD pipeline defined on the .gitlab-ci.yaml file. Feel free to add the variables that you need for your pipeline.
Github project: https://github.com/jelastic/gitlab-k8s-cicd-demo

Now that the CI/CD variables are defined, let’s run the pipeline.
Go to the pipelines section under the CI/CD section and click “Run pipeline”.

Confirm the action by clicking on the “Run Pipeline” button.

Wait until all stages successfully run.

Now on your browser head to your Kubernetes URL.

Add a /helloworld to your URL ( or whatever the context you are using for your application)

Result :

Now to respect the production mode of an application’s lifecycle let’s bind a custom domain name to serve your application.
For that we will:

  1. Add a Load Balancer:
    a. Check the “Change Environment Topology” icon

b. Add a Load Balancer and attach a public IP address to it.

  1. Create an A record for the domain that points to the provided IP address at your domain registrar, you can use any platform of your choice.
  2. Install “Let’s Encrypt SSL Free SSL” Add-On on the Load Balancer.

4. Bind the custom domain name, you previously defined on step2, to the External Doamin(s) field.

5. Finally, you can run the pipeline and use the new domain name to access your application.