Deploy an Quarkus application on GKE with GitLabCI
Tags: quarkus, gitlabci, gke, gitlab
Published: 2020-09-18 05:52:07


In this post, i would like to show you how take advantage of the power of Quarkus and GitLab CI to easily deploy a Rest API on a Google Kubernetes Engine cluster.
You can find the full post (in French 🇫🇷) with the Quarkus explain and configuration [here](https://dev.to/jphi_baconnais/deployer-une-application-quarkus-sur-gke-avec-gitlabci-35ij).


## 🚀 Quarkus

If you don't know **Quarkus**, this is a previous post to a workshop (in French 🇫🇷) [**🚀 Quarkus**](https://dev.to/jphi_baconnais/mes-premiers-tests-avec-quarkus-3jap).

In this example, i make a simple Quarkus application with the kubernetes extension, which allow to return a 200 HTTP code on this REST resource **http://localhost:8080/hello**.

I've changed 2 files :
- the **dockerfile** to build and create runner jar file
- the **application.properties** to change the docker image name

<br />

## 🐬 Google Kubernetes Engine

For this part, i will spare you the step of creating a GKE account.

To create your kubernetes cluster, you have two options:

 - create it with the GKE interface
 - create it with the GitLab interface

For this example i'm going to choose the second option and make full use of the kubernetes integration in GitLabCI to create a GKE cluster. To get started, go to the "Kubernetes" link in the vertical menu :

![Create Cluster](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_create_cluster.png "Create Cluster")

Select cluster creation on GKE :

![Create Cluster GKE](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_create_cluster-2.png "Create Cluster GKE")

Enter the name of the desired cluster :

![Put Cluster Name](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_create_cluster-3.png "Put Cluster Name")

And that's all ! 🤘

![Create Cluster](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_create_cluster-4.png "Quarkus")

On the GKE GUI, our cluster is available :

![Create Cluster](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_create_cluster-gke.png "Quarkus")

<br />

## 🦊 GitLab

Setting up a GitLabCI pipeline is done by creating a **.gitlab-ci.yml** file. If you need some explain, you will find more information on this article - New "publicity" 😎 -to [**🦊 get started with GitLabCI**](https://dev.to/jphi_baconnais/commencer-simplement-avec-gitlabci-53fa). 

We will so create a **.gitlab-ci.yml** file at the root of the project. In this file we will want our script : 
- execute the tests of our application 
- build our docker image via the [**Kaniko librairy**](https://github.com/GoogleContainerTools/kaniko)- deploy our application on Google Kubernetes Engine 

### CI/CD with the .gitlab-ci.yml file

To achieve our 3 jobs, we will create 3 stages :

```
stages:
  - test
  - build_and_push
  - deploy_gke
```
For the first job, all you have to do is make a **mvn clean verify** from a maven 3.6.3 image :

```
🩺 execute test :
    stage: test
    image: maven:3.6.3
    script:
      - mvn clean verify  -f deployquarkusongkewithgitlab/pom.xml
    artifacts:
        paths: 
            - deployquarkusongkewithgitlab/target/kubernetes
```

We set an artifact on the **target/kubernetes** directory in order to limit the number of files available after the execution of the job but also to allow other jobs to be able to use these files.

For the _build_ and _push_ part, the **Kaniko library** will make our job easier :

```
🐳 build push image docker:
  stage: build_and_push
  image:
    name: gcr.io/kaniko-project/executor:debug-v0.19.0
    entrypoint: [""]
  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/deployquarkusongkewithgitlab --dockerfile $CI_PROJECT_DIR/deployquarkusongkewithgitlab/src/main/docker/Dockerfile.jvm --destination deployquarkusgkewithgitlab:dev
```

All you have to do is enter the path to the Dockerfile, a destination and **Kaniko** will build the image for us and push it into the desired repository. In my use, I will be using the [GitLab registry](https://docs.gitlab.com/ee/user/packages/container_registry/). You can better understand why I use the Quarkus setting **quarkus.container-image** 😎.

For the last step, we will simply take a [**cloud-sdk**](https://hub.docker.com/r/google/cloud-sdk/) image from Google on which we will be able to apply our **kubernetes.yaml** file generated by Quarkus.


```
🐋 deploy on gke:
  stage: deploy_gke
  image: google/cloud-sdk
  script:
    - kubectl apply -f deployquarkusongkewithgitlab/target/kubernetes/kubernetes.yml
  environment: gke
```

The **environment** keyword is important and is required for proper integration. This will also allow you to have a view of your environment in the **environment** menu :

![Environment](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_deploy-environment.png "Environment")

In the pipeline we can see that the deployment has been done :

![Deploy success](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_deploy.png "Deploy success")

and that our kubernetes infrastructure is in place and visible under GKE :

![GKE](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_deploy-gke.png "GKE")

Ours pods are available :

![Pods GKE](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_deploy-gke-pod.png "Pods GKE")

<br />

## Supervision 

And as a bonus, to monitor our GKE infrastructure, some metrics are directly available in GitLab :


![Supervision](http://jeanphi-baconnais.gitlab.io/img/deploy_quarkus_gitlabci_gke_deploy-gke-health.png "HealthCheck")

<br />

If you have any comments on this article, please send them to me 😃


<br />