DEV Community

Cover image for Tutorial: Publish a Quarkus application in Kubernetes, Minikube and Dockerhub
Marcus Paulo
Marcus Paulo

Posted on

Tutorial: Publish a Quarkus application in Kubernetes, Minikube and Dockerhub

Notes

This is my first English post, then please give me your feedback, and suggestion to correct any mistakes.

Introduction

The article purpose to create a simple application in Quakus and publish in Minikube (Kubernetes for the local test) and finally publish the image Docker to in Dockerhub.

For more information on these technologies: Kubernetes (K8S), Docker, Minikube, Kubectl e do Quarkus, please visit these sites:

Docker: https://www.docker.com/

Kubernetes: https://kubernetes.io/pt/

Minikube: https://minikube.sigs.k8s.io/docs/start/

Minikube (Kubernetes): https://kubernetes.io/pt/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/

Quarkus: https://quarkus.io/

Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. It is not recommending to production environment.

Prerequisites

Let’s go! We will create a new simple Quarkus application.

Create a simple Quarkus application by command line

mvn io.quarkus:quarkus-maven-plugin:1.13.0.Final:create \\\\    -DprojectGroupId=br.com.mp \\\\    -DprojectArtifactId=kubernetes-quarkus \\\\    -DclassName="br.com.mp.kubernetes.quarkus.rest.GreetingResource" \\\\    -Dpath="/hello" \\\\    -Dextensions="resteasy,kubernetes,jib"
Enter fullscreen mode Exit fullscreen mode

Access the project folder

cd kubernetes-quarkus
Enter fullscreen mode Exit fullscreen mode

In the next step, let’s go to test the project

mvn quarkus:dev
Enter fullscreen mode Exit fullscreen mode

Result in terminal (console)

Running Quarkus application by command line

Running Quarkus application by command line

mvn quarkus:add-extension -Dextensions="quarkus-minikube"
Enter fullscreen mode Exit fullscreen mode

Or you can insert in pom.xml

<dependency>  <groupId>io.quarkus</groupId>  <artifactId>quarkus-minikube</artifactId></dependency>
Enter fullscreen mode Exit fullscreen mode

It is possible to create Quarkus application by command line, adding Minikube extensions.

Creating a local Container Registry in Minikube

It is necessary to set the environment variable with “eval” command.

eval $(minikube -p minikube docker-env)
Enter fullscreen mode Exit fullscreen mode

Create Docker image with Quarkus by command line

Next step, create a maven package with Quarkus parameter to build a container image.

mvn package -Dquarkus.container-image.build=true
Enter fullscreen mode Exit fullscreen mode

Kubernetes and Minikube manifest create

After execute the last command, maven and Quarkus will create the manifest files, located in the folder “/target/kubernetes”, as you see in the image below.

https://cdn-images-1.medium.com/max/1600/1*4sKtcmd1jXa3qd4Kf1B5aw.png

List of all docker images

//List all docker imagesdocker image ls
Enter fullscreen mode Exit fullscreen mode
[output]REPOSITORY                        TAG              IMAGE ID       CREATED         SIZEmarcus/kubernetes-quarkus-teste   1.0.0-SNAPSHOT   e574987218c4   3 minutes ago   199MB
Enter fullscreen mode Exit fullscreen mode

In the next step, we need to apply Minikube manifest to publish in Minikube Kubernetes

kubectl apply -f target/kubernetes/minikube.yml
Enter fullscreen mode Exit fullscreen mode
[output]service/kubernetes-quarkus-teste createddeployment.apps/kubernetes-quarkus-teste created
Enter fullscreen mode Exit fullscreen mode

After a few seconds or minutes, the application is available on Minikube,

Pods are the smallest, most basic deployable objects in Kubernetes (https://cloud.google.com/kubernetes-engine/docs/concepts/pod)

List of all pods

kubectl get po
Enter fullscreen mode Exit fullscreen mode
[output]NAME                                        READY   STATUS    RESTARTS   AGEkubernetes-quarkus-teste-54db4f8df8-gf7nf   1/1     Running   0          6m52s
Enter fullscreen mode Exit fullscreen mode

Access the application at the local machine

To access on the local machine, it is required to redirect Minikube address to localhost, type this command. (Each Pod there is a unique name)

kubectl port-forward pod/kubernetes-quarkus-teste-54db4f8df8-gf7nf 8080:8080
Enter fullscreen mode Exit fullscreen mode
[output]Forwarding from 127.0.0.1:8080 -> 8080Forwarding from [::1]:8080 -> 8080Handling connection for 8080
Enter fullscreen mode Exit fullscreen mode

Access application in browser

Open your browser and insert this address:[http://localhost:8080](http://localhost:8080)

https://cdn-images-1.medium.com/max/1600/1*7Stxh1OQC1cC2YdXiDMIoQ.png

Publish the image to Dockerhub

From now, we are sending our docker image to Dockerhub, with maven command and Quarkus parameter (container image).

mvn clean package -Dquarkus.container-image.push=true
Enter fullscreen mode Exit fullscreen mode

In my case, it happened this error

Caused by: com.google.cloud.tools.jib.api.RegistryUnauthorizedException:Unauthorized for registry-1.docker.io/marcus/kubernetes-quarkus-teste[ERROR]         at com.google.cloud.tools.jib.registry.RegistryEndpointCaller.call(RegistryEndpointCaller.java:164)[ERROR]
Enter fullscreen mode Exit fullscreen mode

For fix this problem, please follow these steps:

1 — Type this command to login on Dockerhub services

docker login
Enter fullscreen mode Exit fullscreen mode

2 — The local Docker image was created with username machine, in my case is marcus/kubernetes-quarkus, but the correct Dockerhub username is marcuspaulo.

Inside the Quarkus project, search application.properties file and insert the line above (with your Dockerhub username)

quarkus.container-image.group=marcuspaulo
Enter fullscreen mode Exit fullscreen mode

Publish in the Dockerhub

mvn clean package -Dquarkus.container-image.push=true
Enter fullscreen mode Exit fullscreen mode

Now, open your browser and access this address: https://hub.docker.com/repositories

I hope that you enjoy this tutorial. Thanks for your attention. Please like and share this post. See you soon.

Source code

https://github.com/marcuspaulo/kubernetes-quarkus

References

https://quarkus.io/guides/container-image#quarkus-container-image_quarkus.container-image.registry

https://quarkus.io/guides/deploying-to-kubernetes

https://quarkus.io/guides/kubernetes-client

https://minikube.sigs.k8s.io/docs/handbook/registry/

https://haralduebele.blog/2020/04/03/deploy-your-quarkus-applications-on-kubernetes-almost-automatically/

https://cloud.google.com/kubernetes-engine/docs/concepts/pod

Top comments (0)