Quarkus - Deploying on OpenShift
This guide covers generating and deploying OpenShift resources based on sane default and user supplied configuration.
To complete this guide, you need:
roughly 5 minutes
JDK 1.8+ installed with
Apache Maven 3.6.2+
access to an OpenShift cluster (Minishift is a viable option)
First, we need a new project that contains the OpenShift extension. This can be done using the following command:
mvn io.quarkus:quarkus-maven-plugin:1.3.2.Final:create \ -DprojectGroupId=org.acme \ -DprojectArtifactId=openshift-quickstart \ -DclassName="org.acme.rest.GreetingResource" \ -Dpath="/greeting" \ -Dextensions="openshift" cd openshift-quickstart
Quarkus offers the ability to automatically generate OpenShift resources based on sane default and user supplied configuration. The OpenShift extension is actually a wrapper extension that brings together the kubernetes and container-image-s2i extensions with sensible defaults so that it’s easier for the user to get started with Quarkus on OpenShift.
When we added the OpenShift extension to the command line invocation above, the following dependency was added to the
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency>
By adding this dependency, we now have the ability to configure the OpenShift resource generation and application using the usual
application.properties approach that Quarkus provides.
The configuration items that are available can be found in:
Furthermore, the items provided by
io.quarkus.deployment.ApplicationConfig affect the OpenShift resources.
Building is handled by the container-image-s2i extension. To trigger a build:
./mvnw clean package -Dquarkus.container-image.build=true
The command above will trigger an s2i binary build.
To trigger a deployment:
./mvnw clean package -Dquarkus.kubernetes.deploy=true
The command above will trigger a container image build and will apply the generated OpenShift resources, right after.
The generated resources are using OpenShift’s
DeploymentConfig that is configured to automatically trigger a redeployment when a change in the
ImageStream is noticed.
In other words, any container image build after the initial deployment will automatically trigger redeployment, without the need to delete, update or re-apply the generated resources.
All available customization options are available in the OpenShift configuration options.
Some examples are provided in the sections below:
To expose a
Route for the Quarkus application:
Tip: You don’t necessarily need to add this property in the
application.properties. You can pass it as a command line argument:
./mvnw clean package -Dquarkus.openshift.expose=true
The same applies to all properties listed below.
To add an annotation in the generated resources:
The command above will add
MY_ENV_VAR=foobar as an environment variable.
Please note that the key
my-env-var will be converted to uppercase and dashes will be replaced by underscores resulting in
You may also noticed that in contrast to labels, and annotations for environment variables you don’t just use a key=value approach. That is because for environment variables there are additional options rather than just value.
To add all key value pairs of a
Secret as environment variables:
The OpenShift extension allows the user to configure both volumes and mounts for the application.
Any volume can be mounted with a simple configuration:
This will add a mount to my pod for volume
my-volume to path
The volumes themselves can be configured as shown in the sections below: