Tutorial: Publish a Quarkus application in Kubernetes, Minikube and Dockerhub
Tags: kubernetes, quarkus, docker, minikube
Published: 2021-04-10 00:51:26

### 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](https://hub.docker.com/).

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

Docker: [https://www.docker.com/](https://www.docker.com/)

Kubernetes: [https://kubernetes.io/pt/](https://kubernetes.io/pt/)

Minikube: [https://minikube.sigs.k8s.io/docs/start/](https://minikube.sigs.k8s.io/docs/start/)

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

Quarkus: [https://quarkus.io/](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

-   Install Docker: [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/)
-   Install Kubernetes: [https://kubernetes.io/pt/docs/setup/](https://kubernetes.io/pt/docs/setup/)
-   Install Kubeclt: [https://kubernetes.io/docs/tasks/tools/](https://kubernetes.io/docs/tasks/tools/)
-   Install Minikube: [https://minikube.sigs.k8s.io/docs/start/](https://minikube.sigs.k8s.io/docs/start/)
-   Install Open JDK 11+: [https://openjdk.java.net/install/](https://openjdk.java.net/install/)

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"
```

### Access the project folder

```
cd kubernetes-quarkus
```

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

```
mvn quarkus:dev
```

### Result in terminal (console)

![Running Quarkus application by command line](https://cdn-images-1.medium.com/max/800/1*1YJUq5GO23ngM3RHTQanpQ.png)

Running Quarkus application by command line

```
mvn quarkus:add-extension -Dextensions="quarkus-minikube"
```

Or you can insert in pom.xml

```
<dependency>  <groupId>io.quarkus</groupId>  <artifactId>quarkus-minikube</artifactId></dependency>
```

> _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)
```

### 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
```

### 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](https://cdn-images-1.medium.com/max/800/1*4sKtcmd1jXa3qd4Kf1B5aw.png)

### List of all docker images

```
//List all docker imagesdocker image ls
```

```
[output]REPOSITORY                        TAG              IMAGE ID       CREATED         SIZEmarcus/kubernetes-quarkus-teste   1.0.0-SNAPSHOT   e574987218c4   3 minutes ago   199MB
```

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

```
kubectl apply -f target/kubernetes/minikube.yml
```

```
[output]service/kubernetes-quarkus-teste createddeployment.apps/kubernetes-quarkus-teste created
```

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_](https://cloud.google.com/kubernetes-engine/docs/concepts/pod)_)_

### List of all pods

```
kubectl get po
```

```
[output]NAME                                        READY   STATUS    RESTARTS   AGEkubernetes-quarkus-teste-54db4f8df8-gf7nf   1/1     Running   0          6m52s
```

### 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
```

```
[output]Forwarding from 127.0.0.1:8080 -> 8080Forwarding from [::1]:8080 -> 8080Handling connection for 8080
```

### 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](https://cdn-images-1.medium.com/max/800/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
```

### 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]
```

For fix this problem, please follow these steps:

1 — Type this command to login on Dockerhub services

```
docker login
```

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](http://application.properties) file and insert the line above (with your Dockerhub username)

```
quarkus.container-image.group=marcuspaulo
```

### Publish in the Dockerhub

```
mvn clean package -Dquarkus.container-image.push=true
```

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

![](https://cdn-images-1.medium.com/max/800/1*r4zFo7nwejzDw4fPWw9_bg.png)

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](https://github.com/marcuspaulo/kubernetes-quarkus)

### References

[https://quarkus.io/guides/container-image#quarkus-container-image_quarkus.container-image.registry](https://quarkus.io/guides/container-image#quarkus-container-image_quarkus.container-image.registry)

[https://quarkus.io/guides/deploying-to-kubernetes](https://quarkus.io/guides/deploying-to-kubernetes)

[https://quarkus.io/guides/kubernetes-client](https://quarkus.io/guides/kubernetes-client)

[https://minikube.sigs.k8s.io/docs/handbook/registry/](https://minikube.sigs.k8s.io/docs/handbook/registry/)

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

[https://cloud.google.com/kubernetes-engine/docs/concepts/pod](https://cloud.google.com/kubernetes-engine/docs/concepts/pod)