Quarkus - Deploying Knative Application to Kubernetes or OpenShift
This guide covers:
The deployment of a serverless application to Kubernetes using Knative.
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 build and route features which are not available in bare Kubernetes.
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
The following script will start minikube and deploy Knative.
./bin/start-minikube.sh eval $(minikube docker-env) (1)
|1||Make the current Docker context to be that of minikube|
Nexus is used for caching maven artifacts so that Apache Maven builds are faster.
kubectl apply -f k8s/nexus.yaml
Wait for some time to have Nexus initialize and run. You can watch the status via
kubectl get pods -w, use Ctrl+c to terminate the watch.
As vanilla Kubernetes does not have an easy and developer friendly way to build and deploy application to a local cluster like minikube, without the need to push the image to external container registry. We will be using Skaffold to help us build and deploy the Quarkus application onto Kubernetes.
The container image will not be pushed to a remote container registry, and hence the container image url has to be
To run Knative Quarkus applications, we need to use the multi stage docker build; to build the Quarkus application container image and use it in Kubernetes application deployment.
The following command start a one time deployment of Quarkus application and runs starts the Knative service after successful container image build.
If you want to deploy a Quarkus JVM image (using HotSpot), then run the following command before running Skaffold:
If you want to deploy a Quarkus Native executable image (using GraalVM), then run the following command before running Skaffold:
It is very important to note that the Dockerfile in
As it will take a few minutes for the build and deployment to be completed you can watch the status using:
watch kubectl get pods
A successful Knative service deployment will show the following pods in the current namespace:
NAME READY STATUS AGE greeter-deployment-5749cc98fc-gs6zr 2/2 Running 10s
|The deployment name could differ in your environment.|
Once the Knative service is successfully running, you can call it using the script
./bin/call.sh, which should return a response like
hello. Allowing it to idle for approximately 60-65 seconds - that is without any further requests -, you will see it automatically scales down to zero pods.
This guide covered the deployment of a Quarkus application as Knative application on Kubernetes 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 scrapable by Prometheus and so on.