Note
|
Red Hat OpenShift Serverless Function is still a Tech Preview feature. If you haven’t installed Knative command (kn) yet, find more information here. In case you want to install kn command tool in the Developer Sandbox, run the following curl command. It will download the kn tool in /tmp directory. curl -L -o /tmp/kn https://github.com/knative/client/releases/download/knative-v1.8.1/kn-linux-amd64 ; chmod a+x /tmp/kn; /tmp/kn version |
Run the following command:
cd ..
kn func create quarkus-func -l quarkus -t cloudevents
The output should look like:
Created quarkus Function in /serverless-workshop/quarkus-func
Inspect the new function project such as func.yaml
and Function.java
.
Deploy the function directly to Red Hat OpenShift. Make sure to change the directory where the func.yaml exists:
Replace YOUR_USERNAME
with your own account in the developer sandbox. You also need to replace YOUR_CONTAINER_REGISTRY
with an external container registry that you want to push the image. For example, quay.io/danieloh30
cd quarkus-func
kn func deploy -r YOUR_CONTAINER_REGISTRY -n YOUR_USERNAME-dev -v
Note
|
In case you want to build the image on macOS M1/M2, you need to append --platform linux/x86_64 to the command line. |
Kn func uses Buildpack tool to build a function and deploy it to Kubernetes or OpenShift. Once the build is completed, you will see the output like:
Waiting for Knative Service to become ready
Function deployed at URL: https://quarkus-func-doh-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com
Go back to the Topology
view in the developer sandbox, you will see a new function deployed. You can also overwrite the Quarkus label by oc command or OpenShift web console:
Send a new cloudevent
message to the new function using Kn func emit:
kn func invoke --content-type="application/json" --data="Daniel Oh" -f=cloudevent -t=YOUR_FUNCTION_URL
The output should look like:
p1.openshiftapps.com
Context Attributes,
specversion: 1.0
type: function.output
source: function
id: ceb3f86a-bc4c-49db-8a82-d69b1ed81aab
datacontenttype: application/json
Data,
{
"message": "Daniel Oh"
}
When you go to the pod logs in OpenShift console, you will see the same cloudevent message output: