Quarkus - Deploying on Kubernetes and OpenShift

This guide covers:

  • The deployment of the application to Kubernetes

  • The deployment of the application to OpenShift

This guide takes as input the application developed in the native application guide.So, you should have been able to package your application as a binary executable, copied it in a Docker image and run this image.

Depending on whether you are a bare Kubernetes user or an OpenShift user, pick the section you need.The OpenShift section leverages OpenShift builds and routes features which are not available in bare Kubernetes.

Prerequisites

For this guide you need:

  • roughly 10 minutes (20 minutes if you want to deploy the application on both platforms)

  • having access to a Kubernetes and/or OpenShift cluster. Minikube and Minishift are valid options.

  • being able to package the docker image from the native application guide

Solution

We recommend to follow the instructions in the next sections and build the application step by step.However, you can go right to the completed example.

Clone the Git repository: git clone https://github.com/quarkusio/quarkus-quickstarts.git, or download an archive.

The solution is located in the getting-started directory.

Deploying the application in Kubernetes

First, you need to push the Docker image (created in the previous guide) to the image registry of your Kubernetes cluster.Depending on your cluster, there are several ways.For minikube, execute:

  1. # For minishift use "eval $(minishift docker-env)" instead
  2. eval $(minikube docker-env)
  3. docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/quickstart .

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

  1. kubectl run quarkus-quickstart --image=quarkus-quickstart/quickstart:latest --port=8080 --image-pull-policy=IfNotPresent
  2. kubectl expose deployment quarkus-quickstart --type=NodePort

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

  1. curl $(minikube service quarkus-quickstart --url)/hello

Deploying the application in OpenShift

In this section, we are going to leverage the build mechanism of OpenShift. Run:

  1. # To build the image on OpenShift
  2. oc new-build --binary --name=quarkus-quickstart -l app=quarkus-quickstart
  3. oc patch bc/quarkus-quickstart -p "{\"spec\":{\"strategy\":{\"dockerStrategy\":{\"dockerfilePath\":\"src/main/docker/Dockerfile.native\"}}}}"
  4. oc start-build quarkus-quickstart --from-dir=. --follow
  5. # To instantiate the image
  6. oc new-app --image-stream=quarkus-quickstart:latest
  7. # To create the route
  8. oc expose service quarkus-quickstart
  9. # Get the route URL
  10. export URL="http://$(oc get route | grep quarkus-quickstart | awk '{print $2}')"
  11. echo "Application URL: $URL"
  12. curl $URL/hello && echo

Your application is accessible at the printed URL.

Going further

This guide covered the deployment of a Quarkus application on Kubernetes and OpenShift.However, there is much more, and the integration with these environments has been tailored to make Quarkus applications execution very smooth.For instance, the health extension can be used for health check; the configuration support allows mounting the application configuration using config map, the metric extension produces data scrappable by Prometheus and so on.