Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Quarkus: A quick-start guide to the Kubernetes-native Java stack

November 11, 2019
Daniel Oh
Related topics:
JavaKubernetes
Related products:
Red Hat OpenShift

Share:

    As immutable infrastructure was starting to hit its stride four or five years ago, one question Java developers were struggling with was: "How do my microservices have to be optimized in Linux container architecture like faster startup and smaller memory footprint?"

    There were a number of limitations to transforming container-native, microservices-based Java technology at the time. One major reason was that the traditional cloud Java stack had to process most of the required tasks, such as annotation scanning, parsing descriptors at runtime rather than build time, until Quarkus came along.

    Quarkus is a Kubernetes-native Java stack tailored for GraalVM and OpenJDK HotSpot. It’s crafted from best-of-breed Java libraries and standards with the following benefits:

    • A cohesive platform for optimized developer joy
      • Live coding and unified configuration
      • No-hassle native executable generation
    • Container-first and Kubernetes-native Java stack
      • Superfast to startup (i.e., 0.055 Seconds for REST + CRUD)
      • Small memory footprint (i.e., 35 MB for REST + CRUD)
    • Unifies Imperative and Reactive development in the same application
      • Inject the EventBus or the Vertx context
      • Use the technology that fits your use-case
      • Key for reactive systems based on event driven apps
    • Extensions for the latest popular open source projects
    Open source logos

    Start coding

    Let’s get started to develop a simple microservice application to expose the REST endpoint from scratch.

    Bootstrapping the project

    Go to Start Coding page in Quarkus.io to bootstrap the first Quarkus application using RESTEasy JAX-RS and REST Clients Extensions:

    Screenshot of steps

    It generates a ZIP file with:

    • The Maven structure
    • An org.acme.ExampleResource resource exposed on /hello
    • An associated unit test
    • A landing page that is accessible on http://localhost:8080 after starting the application
    • Example Dockerfile files for both native and jvm modes
    • The application configuration file

    Unzip and review skeleton codes via your preferred IDE (i.e., VSCode) like:

    unzip code-with-quarkus.zip && cd code-with-quarkus
    code .

    Once you’ve opened an IDE, look at the pom.xml. You will find the import of the Quarkus BOM, allowing you to omit the version on the different Quarkus dependencies. Additionally, you can see the quarkus-maven-plugin responsible for the packaging of the application and for providing the development mode.

    You can see the quarkus-maven-plugin responsible for the packaging of the application and for providing the development mode.

    Running the application using development mode

    To run the application, you need:

    • JDK 1.8+ installed with JAVA_HOME configured appropriately
    • Apache Maven 3.5.3+

    Now you are ready to run your application. Use: mvn compile quarkus:dev:

    INFO] Scanning for projects...
    INFO] ---------------------< org.acme:code-with-quarkus >---------------------
    [INFO] Building code-with-quarkus 1.0.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ code-with-quarkus ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ code-with-quarkus ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- quarkus-maven-plugin:1.0.0.CR1:dev (default-cli) @ code-with-quarkus ---
    Listening for transport dt_socket at address: 5005
    2019-11-09 08:03:20,900 INFO  [io.qua.dep.QuarkusAugmentor] (main) Beginning quarkus augmentation
    2019-11-09 08:03:21,685 INFO  [io.qua.dep.QuarkusAugmentor] (main) Quarkus augmentation completed in 785ms
    2019-11-09 08:03:22,125 INFO  [io.quarkus] (main) Quarkus 1.0.0.CR1 started in 1.364s. Listening on: http://0.0.0.0:8080
    2019-11-09 08:03:22,126 INFO  [io.quarkus] (main) Profile dev activated. Live Coding activated.
    2019-11-09 08:03:22,126 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
    

    Once the application has started, open a web browser to request the provided endpoint: http://localhost:8080/hello

    Once started, open a web browser to request the provided endpoint:  http://localhost:8080/hello

    Change codes

    Modify the return string to “Welcome, Quarkus Cheat Sheet” in hello() method. Remember to save the file:

    public String hello() {
        return "Welcome, Quarkus Cheat Sheet";
    }

    Go back to the web browser then reload the page. The application will be redeployed magically without restarting the runtime:

    The application will be redeployed magically without restarting the runtime.

    Hit CTRL+C to stop the application, but you can also keep it running and enjoy the blazing fast hot-reload.

    Packaging and run the application

    The application is packaged using mvn clean package -DskipTests. It produces two jar files:

    • code-with-quarkus-1.0.0-SNAPSHOT.jar: Containing just the classes and resources of the projects, it’s the regular artifact produced by the Maven build.
    • code-with-quarkus-1.0.0-SNAPSHOT-runner.jar: An executable jar. Be aware that it’s not an über-jar as the dependencies are copied into the target/lib directory.

    Run the application if the endpoint works at the development mode:

    $ java -jar target/code-with-quarkus-1.0.0-SNAPSHOT-runner.jar
    2019-11-09 08:01:14,240 INFO  [io.quarkus] (main) code-with-quarkus 1.0.0-SNAPSHOT (running on Quarkus 1.0.0.CR1) started in 0.660s. Listening on: http://0.0.0.0:8080
    2019-11-09 08:01:14,289 INFO  [io.quarkus] (main) Profile prod activated. 
    2019-11-09 08:01:14,289 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
    
    // Run the curl command in a new terminal 
    $ curl http://localhost:8080/hello
    Welcome, Quarkus Cheat Sheet

    Building a native executable

    Let’s now produce a native executable for our application. It improves the startup time of the application and produces a minimal disk footprint. The executable would have everything to run the application including the "JVM" (shrunk to be just enough to run the application) and the application.

    The executable would have everything to run the application including the "JVM" (shrunk to be just enough to run the application) and the application.

    Install GraalVM and configure the environment

    To build a native executable image, you need:

    • Install GraalVM community edition at least version 19.1.1 in GraalVM web site.
    • Run gu install native-image from your GraalVM directory
    • The GRAALVM_HOME environment variable configured as below:

    Linux:

    export GRAALVM_HOME=$HOME/Development/graalvm/

    macOS:

    export GRAALVM_HOME=$HOME/Development/graalvm/Contents/Home/

    Before going further, be sure that the GRAALVM_HOME environment variable is configured appropriately.

    You will use “native” profile to build a native executable image in the pom.xml:

    You will use “native” profile to build a native executable image in the pom.xml.

    Create a native executable and run it

    Run mvn clean package -DskipTests -Pnative. It will take a few minutes to produce the image:

    
    ...
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]     (clinit):     438.26 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]     universe:   1,174.98 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]      (parse):   2,329.86 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]     (inline):   3,247.13 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]    (compile):  27,917.55 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]      compile:  35,768.02 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]        image:   2,067.69 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]        write:     885.91 ms
    [code-with-quarkus-1.0.0-SNAPSHOT-runner:86834]      [total]:  70,647.15 ms
    [INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 73212ms
    [INFO] ------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------
    [INFO] Total time:  01:17 min
    [INFO] Finished at: 2019-11-09T08:05:40+09:00
    [INFO] ------------------------------------------------------------------
    

    Let’s run the native executable:

    
    ./target/code-with-quarkus-1.0.0-SNAPSHOT-runner
    2019-11-09 08:07:24,786 INFO  [io.quarkus] (main) code-with-quarkus 1.0.0-SNAPSHOT (running on Quarkus 1.0.0.CR1) started in 0.013s. Listening on: http://0.0.0.0:8080
    2019-11-09 08:07:24,787 INFO  [io.quarkus] (main) Profile prod activated. 
    2019-11-09 08:07:24,787 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
    

    It takes just 13 milliseconds to run our microservices. You will find the same result exactly when you go back to the web browser then reload the endpoint page:

    You will find the same result exactly when you go back to the web browser then reload the endpoint page.

    Hit CTRL+C to stop the application before moving to the next step.

    Deploying on Kubernetes

    Now, you will deploy the optimized microservice application on immutable infrastructure, Kubernetes cluster. You can install own Kubernetes cluster here.

    Containerize the application

    The project generation has provided a Dockerfile.native in the src/main/docker directory with the following content:

    FROM registry.access.redhat.com/ubi8/ubi-minimal
    WORKDIR /work/
    COPY target/*-runner /work/application
    RUN chmod 775 /work
    EXPOSE 8080
    CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

    Then, you need to push the Docker image to the image registry of your Kubernetes cluster. Depending on your cluster, there are several ways. For Minikube, execute:

    eval $(minikube docker-env)
    
    docker build -f src/main/docker/Dockerfile.native -t 
    quarkus-cheatsheet/myapp .

    Deploy the application in Kubernetes

    Once the image has been pushed to the Kubernetes image registry, instantiate the application as follows:

    kubectl run quarkus-cheatsheet --image=quarkus-cheatsheet/myapp:latest --port=8080 --image-pull-policy=IfNotPresent
    
    kubectl expose deployment quarkus-cheatsheet --type=NodePort

    The application is now exposed as an internal service. If you are using Minikube, you can access it using:

    curl $(minikube service quarkus-quickstart --url)/hello
    
    Welcome, Quarkus Cheat Sheet

    More Quarkus guides

    • Get started with Quarkus course (estimated time: 10 minutes)
    • Red Hat Developer Quarkus courses
    • Get started with Eclipse Che 7 and Quarkus: An overview
    • Quarkus: Supersonic, subatomic Java
    • From zero to Quarkus and Knative: The easy way
    • Create your first Quarkus project with Eclipse IDE (Red Hat CodeReady Studio)

    The Quarkus site provides additional practical and useful guides on how to develop microservices/cloud-native apps/serverless using Quarkus extensions with common use cases:

    • Contexts and Dependency Injection
    • Using SSL With Native Images
    • Using JWT RBAC
    • Simplified Hibernate ORM with Panache
    • Using Apache Kafka Streams
    • Using Keycloak to Protect JAX-RS Applications
    • Deploying Native Applications on Kubernetes or OpenShift
    • Using OpenTracing and Collecting Metrics
    • Building Applications with Maven
    • Using the Quarkus Extension for Spring DI API
    Last updated: January 13, 2022

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue