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.
π Quarkus
If you don't know Quarkus, this is a previous post to a workshop (in French π«π·) π Quarkus.
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
π¬ 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 :
Select cluster creation on GKE :
Enter the name of the desired cluster :
And that's all ! π€
On the GKE GUI, our cluster is available :
π¦ 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.
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- 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. You can better understand why I use the Quarkus setting quarkus.container-image π.
For the last step, we will simply take a 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 :
In the pipeline we can see that the deployment has been done :
and that our kubernetes infrastructure is in place and visible under GKE :
Ours pods are available :
Supervision
And as a bonus, to monitor our GKE infrastructure, some metrics are directly available in GitLab :
If you have any comments on this article, please send them to me π
Top comments (0)