Kubernetes native application with Quarkus

A Guide to Execute Quarkus Applications on Kubernetes

Silas Candiolli
abbeal’s tech blog
5 min readOct 19, 2023

--

Java turned 28 in 2023, it is a big milestone for a platform that has already had its death prophesied so many times. The fact is that people trust Java and what it delivers, trust the evolution it has been undergoing and the way it solves problems.

Java has a very strong community that knows how to make the right decisions so that Java will not die. This community also contributed to language and virtual machine improvements.

Java has also gained the trust of large companies around the world. Most large banks in Brazil and Latin America use Java in the back-end, such as Banco do Brasil and Itaú. BNY Melon, from New York, is a bank that provides loans to other banks around the world and uses Java as well. Of course, the biggest companies in technology like IBM, Red Hat, Amazon, Google and Microsoft are using Java as well.
So, these are some examples of those who are interested in making Java run on the Cloud, because it is simple: knowledge and money.

Some challenges on the way

Anyone who has known Java long enough knows that running Java in the Cloud is a considerable challenge. While reliable, Java was created in a context where large monoliths were a necessity.
But when we talk about microservices the context changes, now there is independence between services, and a low startup time and low memory requirement are expected.
Also, portability matters too. Nowadays there is a lot of competition between Cloud servers, and there is also talk about multi-cloud, so having the power to run your App on AWS today and tomorrow on Google Cloud is also becoming a necessity. I haven’t particularly seen it happen in the big clients I’ve worked with, maybe it takes a while for it to be something normal, but it seems to be a trend.

Kubernetes extension for Quarkus

Because of that, I would like to write about Quarkus and its extension for Kubernetes, and how it came to help the teams to run Java on the Cloud.

Some people call Quarkus a framework, but I see some refer to it as a platform. I really like it and I also see Quarkus as a platform, it is more than a framework.
When adding extensions to your application they will already be pre-configured to be used, it’s good because it doesn’t require a lot of prior knowledge about the libraries you choose to use, you can use and learn during development, make improvements and configure adjustments later when you have more clarity of what you want.

So what does a Kubernetes extension offer to you:

Single-step Deployment

Quarkus makes it easy to deploy microservice applications to Kubernetes without having to understand the intricacies of the underlying Kubernetes framework

— quarkus.io

The strong integration of Quarkus with Kubernetes makes possible something that is not simple, nor normal, for most developers, and I include myself in that group.
Nowadays it is very normal to have teams focused on infrastructure, so the developer doesn’t have to worry about how and where the application will run. But on the other hand, the more experienced we become as developers, the more important it is to understand these details.

Having Quarkus as a ready-made platform to build a Docker image of your Java app and deploy it to Kubernetes is amazing. From my point of view, this opens many doors for those who are starting and need to see things running quickly. Maybe someone who is starting in the area of programming and studying Java, or an entrepreneur who wants to have his product in a cloud. But, making this integration simpler to do helps to popularize the technology, and that is good for everyone.

Tracing, Debugging, Health Check and Metric

Quarkus also has an extension for observability. Opentelemetry is used to get metrics and logging by your software and has faster troubleshooting.

For health checks and metrics, you can use the SmallRye. Can you imagine the chaos that could be to not know what is happening with specific microservices in production on Black Friday night?

Application configuration

Did you already need to config credentials to consume an API or connect to Databases? Well, the right way to do that is by using Secrets and ConfigMap as a configuration source, to avoid having passwords in your properties files. To help you with that there is the Kubernetes Config

Remote development

Using the Kubernetes extension together with that of your cloud provider, it is possible to configure Remote Development, which makes it possible to use Living Code by deploying in the cloud.
Maybe this makes more sense for small projects. Where you have fewer processes, environments and cycles.

Hands-on

To follow the steps and execute this project on your machine, we will use these tools:

Now, let's see how easy it is to deploy a Quarkus App on Kubernetes.

  1. First, start the Docker and Minikube. Then, after that, you can create a new project and add new extensions:
// Start docker
docker start

// Start Minikube
minikube start

// Create a new Quarkus project
quarkus create app com.silascandiolli:qstart

// Add new extensions
quarkus extension add 'quarkus-kubernetes'
quarkus extension add 'smallrye-health'

2. Now, you should open your new project application.properties file, and add the Kubernetes properties. It is important to say that you have to replace “youruser” for your current Docker Hub username:

quarkus.container-image.group=youruser
quarkus.container-image.username=youruser
quarkus.container-image.tag=latest

3. Once your project is ready, you could package the code, build the Docker image and push it to your Docker hub (do not forget to log in to Docker Hub):

./mvnw package -DskipTests
docker build -f src/main/docker/Dockerfile.jvm -t silasca/qstart .
docker login
docker image push silasca/qstart

4. Now it is time to deploy on Minikube, and make it available on port 8080:

kubectl apply -f target/kubernetes/kubernetes.yml
kubectl port-forward pod/qstart-xxxx 8080:8080

5. Checking the Minikube running pods:

kubectl get pods -w

6. Testing the resources:

curl localhost:8080/hello/silas
curl localhost:8080/hello
curl localhost:8080/q/health

Final considerations

I hope this guide can help you to start and go deep into Quarkus. If you have any questions, please let me know, I will be pleased to help you in your journey.

--

--