Using Quarkus to Run Java Apps on Kubernetes
This developer runs a quick test of the recently announced Quarkus framework from Red Hat.
Join the DZone community and get the full member experience.
Join For Freea few weeks ago, red hat introduced quarkus, which is a "next-generation kubernetes-native java framework" that is available as open source . quarkus promises really fast boot times and low memory usages. this makes quarkus a perfect fit for java workloads running as microservices on kubernetes as well as java workloads running as serverless functions.
read the article, " why quarkus " to learn how quarkus works. in a nutshell, quarkus compiles java source code in native binaries via graalvm . the quarkus framework helps developers to easily build applications that can leverage the graalvm benefits.
i did some first quick tests to check how difficult it is to use quarkus for my cloud-native starter sample. one of my microservices uses javaee and eclipse microprofile. as documented on the microprofile blog , microprofile can be used together with quarkus.
my sample service is pretty simple and basically provides only a rest api. it uses a "classic" javaee stack. read my article dockerizing java microprofile applications for details about the exact stack i'm using.
what i like most about quarkus is that i can run my existing microprofile application with little changes only!
using quarkus was pretty straight forward. all i had to do was to exchange the dockerfile
from registry.fedoraproject.org/fedora-minimal
workdir /work/
copy target/*-runner /work/application
run chmod 775 /work
expose 8080
cmd ["./application", "-dquarkus.http.host=0.0.0.0"]
...and to change the pom.xml file:
<dependency>
<groupid>org.eclipse.microprofile</groupid>
<artifactid>microprofile</artifactid>
<version>2.1</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
<dependency>
<groupid>io.quarkus</groupid>
<artifactid>quarkus-arc</artifactid>
</dependency>
<dependency>
<groupid>io.quarkus</groupid>
<artifactid>quarkus-resteasy</artifactid>
<version>0.11.0</version>
</dependency>
in order to deploy the quarkus service to kubernetes, i wrote a little script . in the first step, the java code is compiled via graalvm into a native binary. after this, a docker image is built that contains and runs the native binary on a 'fedora-minimal' image.
mvn -f ${root_folder}/articles-java-jee/pom-quarkus.xml package -pnative -dnative-image.docker-build=true
docker build -f ${root_folder}/articles-java-jee/dockerfile.quarkus -t articles-quarkus:1 .
kubectl apply -f deployment/kubernetes-quarkus.yaml
after this i can run the "classic" articles service and the quarkus-based version in the same way.

the results are amazing. the size of the "classic" image is 462 mb, while the quarkus image is only 128 mb big.
note : i haven't optimized the "classic" stack at all. for example, i included many features i don't really need. keep this in mind for the comparison.

in my local minikube cluster, the startup time of the classic container (including ssl certificate creation, openapi explorer, etc.) took 5 seconds, while quarkus started in 0.003 seconds.

more interesting than the startup time of the containers is the overall duration, how long it takes to create a new kubernetes deployment (
kubectl apply ...yaml
). i haven't done extensive testing, but here are some interesting numbers. i measured the time how long it takes for minikube to start both containers (including the istio proxy) in the pod after the images have been built and pushed. for the "classic" version this takes roughly 46 seconds, for the quarkus based version it takes about 6 seconds only.
if you want to give it a try yourself, check out my repo and run the script above.
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Beginner Intro to Real-Time Debugging for Mobile Apps: Tools and Techniques
-
Building Resilient Systems With Chaos Engineering
-
What Is End-To-End Testing? E2E Testing Tutorial With Examples and Best Practices
-
Apache Cassandra With Java: Introduction to UDT
Comments