In this unit, you will deploy the exsisting Todo application as a serverless function to the Azure Red Hat OpenShift environment.
Quarkus offers Funqy extensions, enabling you to create a portable Java API for deploying functions on various serverless platforms like OpenShift Serverless (Knative), AWS Lambda, Azure Functions, and Google Cloud Functions. Unlike direct Azure Functions, Quarkus functions on OpenShift Serverless on ARO can be compiled into native executables, resulting in faster cold starts and significantly reduced memory footprints.
Install the OpenShift Serverless ane Knative Serving Custom Resource (CR) with the following documents:
You should see the deployed pods when you have successfully installed the OpenShift Serverless:
Update the following values in src/main/resources/application.properties
to keep the existing Todo data and deploy the application as the serverless function:
%prod.quarkus.kubernetes.deployment-target=knative
Append the following variables in src/main/resources/application.properties
:
%prod.quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000
Note that if you want to build a native executables on macOS
, add the following configuration to use Linux binary file format:
%prod.quarkus.native.container-build=true
Before the build, delete existing todo
application by the following oc
command:
Note
If you haven't installed the OpenShift CL yet, you can install it by following this link.
oc delete all --all
Build the native executables then deploy it to ARO. Run the following Quarkus CLI which will build and deploy using the OpenShift extension:
quarkus build --no-tests --native
The output should end with BUILD SUCCESS
.
Edit the label of the serverless function pod to use the Quarkus icon.
oc label rev/quarkus-todo-app-aro-00001 app.openshift.io/runtime=quarkus --overwrite
If your application name is not "quarkus-todo-app-aro", you need to change it in the above oc
command.
The output should look like:
revision.serving.knative.dev/quarkus-todo-app-aro-00001 labeled
Go back to the Topology view, you should see the serverless function pods running. The pod will scale down to zero
if you didn't send traffic in 30
seconds.
Copy the Route URL
to clipboard.
Access the REST API (/api/) to get all Todo items in the Azure PostgreSQL database. You need to replace ROUTE-URL
with your serverless function url in the OpenShift cluster.
curl http://ROUTE-URL/api ; echo
The output should look like:
[
{
"completed": false,
"id": 1,
"order": 0,
"title": "Introduction to Quarkus",
"url": null
},
{
"completed": false,
"id": 2,
"order": 1,
"title": "Hibernate with Panache",
"url": null
},
{
"completed": false,
"id": 3,
"order": 2,
"title": "Visit Quarkus web site",
"url": "https://quarkus.io"
},
{
"completed": false,
"id": 4,
"order": 3,
"title": "Visit Azure Red Hat OpenShift",
"url": "https://azure.microsoft.com/en-us/products/openshift"
}
]
You can also see that the servereless function pod has scaled up again in the Topology view.
Great! You have successfully deployed the serverless function to ARO.