Deploying your Serverless Workflow application on Kubernetes

This document describes how to deploy a Kogito Serverless Workflow application using a Kubernetes cluster, along with a procedure to run the Knative platform.

Prerequisites

Before proceeding further, make sure that you have access to the Kubernetes cluster with Knative available.

Verifying Knative availability on Kubernetes

To make sure Knative is available, it can be checked with the commands below:

Verify if Knative is available
kubectl get services -n knative-serving
NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                   AGE
activator-service            ClusterIP   10.97.110.167    <none>        9090/TCP,8008/TCP,80/TCP,81/TCP,443/TCP   44m
autoscaler                   ClusterIP   10.98.64.78      <none>        9090/TCP,8008/TCP,8080/TCP                44m
autoscaler-bucket-00-of-01   ClusterIP   10.111.19.134    <none>        8080/TCP                                  44m
controller                   ClusterIP   10.98.150.141    <none>        9090/TCP,8008/TCP                         44m
default-domain-service       ClusterIP   10.106.202.150   <none>        80/TCP                                    43m
domainmapping-webhook        ClusterIP   10.102.87.208    <none>        9090/TCP,8008/TCP,443/TCP                 44m
net-kourier-controller       ClusterIP   10.100.120.208   <none>        18000/TCP                                 43m
webhook                      ClusterIP   10.108.153.180   <none>        9090/TCP,8008/TCP,443/TCP                 44m

For more information on how to figure out if Knative is installed please refer to this link. If not, follow the installation steps described in the Knative documentation.

Deploying your workflow application on Kubernetes

Once Knative is ready, you can initiate the process of deploying your Kogito Serverless Workflow application on Kubernetes.

Prerequisites

By default, Kubernetes does not have any registry installed. You can check with the administrator if a private registry is available. Otherwise, you can publish the Application Container image on the Quay.io, or on any other registry of your preference.

If the registry requires authentication you need to create a Pull Secret with the registry credentials, for more information please take a look in this link.

Procedure
  1. Create serverless-workflow-greeting-quarkus namespace using the following command:

    Create namespace
    kubectl create namespace serverless-workflow-greeting-quarkus
  2. Set the Kubernetes context to the newly created namespace using the following command:

    Set Kubernetes context to a namespace
    kubectl config set-context --current --namespace=serverless-workflow-greeting-quarkus

    After setting the context, all kubectl commands will use the selected namespace.
    You can use the following command to verify the current namespace:

    Verify the current namespace
    kubectl config view --minify -o jsonpath='{..namespace}'
  3. Deploy your Kogito Serverless Workflow application on Kubernetes.

    The next step is to deploy your workflow application and execute it. You can read the further sections on the different procedures to deploy your Kogito Serverless Workflow application.

    You can use the native image due to the faster startup.
    For more information about installing the workflow application, see Building workflow images using Quarkus CLI document.

In the following procedures, you can find two examples of deploying your workflow application, including:

For this tutorial, we use the default-domain provided by Knative that configures Knative Serving to use the Magic DNS for naming resolution, for more details please check the Knative documentation.

Deploying your workflow application using Knative CLI

Once you have pushed your workflow application into the target registry, you can use the command-line tools, such as Knative CLI or kubectl to initiate the deployment process.

Prerequisites
Procedure
  1. In a command terminal, execute the following command to deploy your workflow application using Knative CLI:

    Example of deploying workflow application using Knative CLI
    kn service create hello \
        --image=quay.io/mynamespace/serverless-workflow-greeting-quarkus:1.0 \
        --pull-policy=IfNotPresent \
        --port 8080
    Example output
    Creating service 'hello' in namespace 'serverless-workflow-greeting-quarkus':
    
      0.066s The Route is still working to reflect the latest desired specification.
      0.099s ...
      0.322s Configuration "hello" is waiting for a Revision to become ready.
      4.885s ...
      5.061s Ingress has not yet been reconciled.
      5.322s Waiting for load balancer to be ready
      5.460s Ready to serve.
    
    Service 'hello' created to latest revision 'hello-00001' is available at URL:
    http://hello.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io

Verify if the workflow application is deployed correctly:

  • On kubectl

  • On Knative CLI

kubectl get services.serving.knative.dev greeting-quarkus-cli
kn service list greeting-quarkus-cli
Example output
NAME                   URL                                                                                      LATEST                       AGE    CONDITIONS   READY   REASON
greeting-quarkus-cli   http://greeting-quarkus-cli.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io   greeting-quarkus-cli-00001   7m6s   3 OK / 3     True
Use the URL in the output to send request to your workflow application.
Example request
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John", "language": "English"}' http://hello.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io/jsongreet
Example response
{"id":"0f77abce-837e-4bd2-b4f1-a0e5e0265fcb","workflowdata":{"name":"John","language":"English","greeting":"Hello from JSON Workflow, "}}

Deploying your workflow application using kubectl

You can also use kubectl command-line interface and plain Kubernetes objects to deploy your workflow application.
And, instead of creating knative yaml|json descriptors, you can leverage the Quarkus Kubernetes extension and Kogito Knative add-on to generate the descriptors.

Prerequisites
  • Kogito Workflow application ready to use.

  • kubectl command-line tool is installed.

  • (Optional) Quarkus CLI is installed
    For more information about installing the Quarkus CLI, see Installing the Quarkus CLI.

Procedure
  1. Add the Quarkus extensions to generate knative yaml|json descriptors.

    To use the Quarkus Kubernetes extension and Kogito Knative add-on, ensure that the following dependencies are available in the pom.xml file and Gradle:

    • pom.xml

    • Gradle

    <dependency>
      <groupId>org.kie.kogito</groupId>
      <artifactId>kogito-addons-quarkus-knative-eventing</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-kubernetes</artifactId>
    </dependency>
    quarkus-kubernetes 'io.quarkus:quarkus-kubernetes:2.16.6.Final'
    quarkus-kubernetes 'org.kie.kogito:kogito-addons-quarkus-knative-eventing:1.39.0.Final'
  2. To generate the knative yaml|json descriptors, set the following properties in the application.properties file of your workflow application:

    System properties to generate knative descriptors
    quarkus.kubernetes.deployment-target=knative
    quarkus.knative.name=greeting-quarkus-kubectl
  3. Build your workflow application.

    Once you have built your application, you can find the generated descriptors files in the target/kubernetes directory:

    • knative.json

    • knative.yml

    Following is an example of the generated files:

    Knative descriptor example for a workflow application
    ---
    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      annotations:
        app.quarkus.io/commit-id: 06c3fe8e2dfc42e2211cbcc41224f5a3d6bd1f26
        app.quarkus.io/build-timestamp: 2022-06-23 - 23:53:38 +0000
      labels:
        app.kubernetes.io/name: greeting-quarkus-kubectl
      name: greeting-quarkus-kubectl
    spec:
      template:
        metadata:
          labels:
            app.kubernetes.io/name: greeting-quarkus-kubectl
        spec:
          containerConcurrency: 0
          containers:
            - image: quay.io/mynamespace/serverless-workflow-greeting-quarkus:1.0-native
              livenessProbe:
                failureThreshold: 3
                httpGet:
                  path: /q/health/live
                  port: null
                  scheme: HTTP
                initialDelaySeconds: 0
                periodSeconds: 30
                successThreshold: 1
                timeoutSeconds: 10
              name: greeting-quarkus-kubectl
              ports:
                - containerPort: 8080
                  name: http1
                  protocol: TCP
              readinessProbe:
                failureThreshold: 3
                httpGet:
                  path: /q/health/ready
                  port: null
                  scheme: HTTP
                initialDelaySeconds: 0
                periodSeconds: 30
                successThreshold: 1
                timeoutSeconds: 10

    Once the files are generated, you might be required to add the imagePullPolicy manually before deploying the workflow application.

    Some system properties are not working properly due to a bug in the Decorate API. For more information about the bug, see the Quarkus issue.

    There is a small bug on the Decorate API where some system properties are not taking effect, for more information take a look at this Quarkus issue. After the file generation, you might be required to add the imagePullPolicy manually before deploying it.

  4. Enter the following command to deploy the workflow application using kubectl:

    Deploy the workflow application using kubectl
    kubectl apply -f target/kubernetes/knative.yml

Verify if the workflow application is deployed correctly:

  • On kubectl

  • On Knative CLI

kubectl get services.serving.knative.dev greeting-quarkus-cli
kn service list greeting-quarkus-cli
Example output
NAME                   URL                                                                                      LATEST                       AGE    CONDITIONS   READY   REASON
greeting-quarkus-cli   http://greeting-quarkus-cli.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io   greeting-quarkus-cli-00001   7m6s   3 OK / 3     True
Use the URL in the output to send request to your workflow application.
Example request
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John", "language": "English"}' http://hello.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io/jsongreet
Example response
{"id":"0f77abce-837e-4bd2-b4f1-a0e5e0265fcb","workflowdata":{"name":"John","language":"English","greeting":"Hello from JSON Workflow, "}}

Deploying your workflow application using Quarkus CLI

Prerequisites
Procedure
  1. Add the Quarkus extensions to deploy the knative service

    You can add the Kubernetes and the Kogito Knative extensions to your project with the Quarkus CLI:

    Add kubernetes and Kogito knative extensions to the project with Quarkus CLI
    quarkus extension add kubernetes
    quarkus extension add kogito-addons-quarkus-knative-eventing
  2. To deploy your workflow application using Quarkus CLI, set the following system properties in application.properties file:

    Required system properties
    quarkus.knative.name=greeting-quarkus-cli (1)
    quarkus.kubernetes.deployment-target=knative (2)
    quarkus.kubernetes.deploy=true (3)
    quarkus.container-image.push=true (4)
    quarkus.container-image.group=kiegroup (5)
    quarkus.container-image.registry=quay.io (6)
    quarkus.container-image.tag=1.0-SNAPSHOT (7)
    1 Property to set the Knative service name
    2 Property to set the target deployment type
    3 Property to set whether or not deploy on an active Kubernetes cluster
    4 Property to whether or not push images
    5 Property to define which registry group/namespace the built image belongs to
    6 Property to define to which registry the built image will be pushed to
    7 Sets the built Container image tag

    This feature works with Quarkus 2.10.2.Final or later. For more information, see link.

Build and Deploy your workflow application
quarkus build -- -Pcontainer -DskipTests \
  -Dquarkus.container-image.push=true \
  -Dquarkus.container-image.registry=quay.io \
  -Dquarkus.container-image.group=kiegroup \
  -Dquarkus.container-image.tag=1.0-SNAPSHOT

Note that the maven profile activated is named as container, which provides the needed system properties to build the target container image.

Verify if the workflow application is deployed correctly:

  • On kubectl

  • On Knative CLI

kubectl get services.serving.knative.dev greeting-quarkus-cli
kn service list greeting-quarkus-cli
Example output
NAME                   URL                                                                                      LATEST                       AGE    CONDITIONS   READY   REASON
greeting-quarkus-cli   http://greeting-quarkus-cli.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io   greeting-quarkus-cli-00001   7m6s   3 OK / 3     True
Use the URL in the output to send request to your workflow application.
Example request
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John", "language": "English"}' http://hello.serverless-workflow-greeting-quarkus.10.103.94.37.sslip.io/jsongreet
Example response
{"id":"0f77abce-837e-4bd2-b4f1-a0e5e0265fcb","workflowdata":{"name":"John","language":"English","greeting":"Hello from JSON Workflow, "}}

Found an issue?

If you find an issue or any misleading information, please feel free to report it here. We really appreciate it!