Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Build a Kogito Serverless Workflow using Serverless Framework

September 28, 2022
Daniele Martinoli
Related topics:
Serverless
Related products:
Red Hat OpenShift Container Platform

Share:

    Serverless Workflow is a standard from the Cloud Native Computing Foundation (CNCF). Kogito implements the Serverless Workflow specifications to define workflows for event-driven, serverless applications using a DSL-based model.

    Serverless Framework is an open source framework that builds, compiles, and packages code for serverless deployment. The framework provides implementations for different cloud providers, including Knative.

    This article walks you through the steps to integrate Kogito with Serverless Framework to build a working example on the Red Hat OpenShift Platform. The article is based on code you can find in my GitHub repository.

    Prerequisites

    To run the demo in this article, you need the following tools on your local system:

    • Maven (at least 3.8.6)
    • Java SDK 11+
    • Docker
    • Bash terminal
    • The serverless command-line interface (CLI) from the Serverless Framework

    You also need accounts on the following systems:

    • OpenShift 4.8+ (logged in as an account with the cluster-admin role)
    • A Docker Hub credential
    • A Quay.io account

    Introducing the Kogito Newsletter Subscription Showcase example

    The Kogito Newsletter Subscription Showcase is a demo based on the Kogito implementation of the Serverless Workflow specification. This example consists of two applications:

    • subscription-flow: The workflow orchestrator, defined using the Serverless Workflow specification
    • subscription-service: A Quarkus application implementing the orchestrated services.

    Figure 1 shows the system architecture of the example application.

    The Newsletter Subscription Showcase is made of two applications, the Subscription Flow and the Subscription Service, an event Broker and a Persistent Storage
    Figure 1: The architecture of the Newsletter Subscription Showcase example.
    Created by KIE group, License under Apache 2.0. Thanks to KIE https://www.kie.org/,

    The documentation in the repository describes how to deploy and run the application on Knative, using the YAML configurations generated by the Maven build of the project, through the knative build profile, running on minikube.

    This article shows how to implement the same deployment in the cloud using the Serverless Framework. Our target is a Knative environment installed on OpenShift, but the principles extend to other cloud settings as well.

    Images for the Kogito Newsletter Subscription Showcase

    The first step is to build and publish the images of the two applications that make up the Newsletter Subscription Showcase example: subscription-flow and subscription-service.

    You can download prebuilt images or build new ones from source. The prebuilt images for our example are available in the quay.io/dmartino repository; if you download them, you can skip ahead to the next section, entitled "Installing Knative on OpenShift."

    If you prefer to build the images yourself, you'll need to clone the Kogito Examples repository, build the applications using the knative profile, and finally push the Docker images to your Quay repository, using the following commands. Replace QUAY_USER_ID with your actual ID.

    git clone https://github.com/kiegroup/kogito-examples.git
    cd kogito-examples
    git checkout stable
    cd serverless-workflow-examples/serverless-workflow-newsletter-subscription
    docker login quay.io
    mvn clean install -DskipTests -Pknative \
      -Dquarkus.container-image.registry=quay.io \
      -Dquarkus.container-image.group=QUAY_USER_ID \
      -Dquarkus.container-image.push=true

    Verify that two images have been generated with the expected tag (as of today, it is 1.25.0.Final) on your Quay.io account, and modify the visibility of the images to make them publicly accessible.

    Installing Knative on OpenShift

    Knative can be easily installed on OpenShift using the OpenShift Serverless Operator, and this is the recommended approach we are going to follow.

    Install the Red Hat Serverless Operator from the administrator console (Figure 2). The sequence of menu items to choose is OperatorHub→Red Hat OpenShift Serverless→Install. Accept the default settings.

    Administrator console -> OperatorHub -> Red Hat OpenShift Serverless -> Install using the default settings.
    Figure 2: Select the Red Hat OpenShift Serverless operator from the OperatorHub page and install it using the default settings.

    One instance of the KnativeServing custom resource is required to manage Knative serverless applications (Figure 3). Create the instance in the knative-serving namespace by selecting the knative-serving project from the administrator console. Then select Installed Operators→Red Hat OpenShift Serverless→Knative Serving→Create KnativeServing. Accept the default settings.

    Administrator console -> Project: knative-serving -> Installed Operators -> Red Hat OpenShift Serverless -> Knative Serving -> Create KnativeServing using the default settings.
    Figure 3: Install the KnativeServing custom resource from the knative-serving project.

    Additionally, one instance of the KnativeEventing Custom Resource is required to manage the events around the Knative serverless applications (Figure 4). Create the instance in the knative-eventing namespace by selecting the knative-eventing project from the administrator console. Then select Installed Operators→Red Hat OpenShift Serverless→Knative Eventing→Create KnativeEventing. Accept the default settings.

    Administrator console -> Project: knative-eventing -> Installed Operators -> Red Hat OpenShift Serverless -> Knative Eventing -> Create KnativeEventing using the default settings.
    Figure 4: Install the KnativeEventing custom resource from the knative-eventing project.

    Installing the example application

    To run the application, you need to install a PostgreSQL database. The application also requires some configuration changes to bring it up to date.

    Installing the newsletter-postgres service

    The newsletter-postgres service is a regular OpenShift deployment of PostgreSQL in a namespace called newsletter-subscription-db. Execute the following instructions to install the newsletter-postgres service:

    git clone https://github.com/dmartinol/kogito-serverless-workflow-with-serverless-framework.git
    cd kogito-serverless-workflow-with-serverless-framework
    oc create namespace newsletter-subscription-db
    oc adm policy add-scc-to-user anyuid -z default -n newsletter-subscription-db
    oc apply -f newsletter-postgres/newsletter-postgres.yaml

    Preparing the Serverless Framework

    To successfully run the example on OpenShift, we had to apply a few changes to the original implementation of the Knative Cloud Provider in the Serverless Framework. Such updates are needed to align the original Knative version to the one installed with the OpenShift Serverless Operator, and to introduce some extensions that support new settings and fix a few issues. Details are available in a GitHub repository.

    Because the example would not run using the default implementation of the Knative Cloud Provider, the package.json descriptor includes the following dependency:

      "devDependencies": {
        "serverless-knative": "https://github.com/dmartinol/serverless-knative.git"
      }

    The necessary changes are available in the following GitHub repositories:

    • Serverless Knative Plugin: The Knative Cloud Provider implementation for the Serverless Framework
    • knative-serving: A Node.js module to manage Knative Serving instances
    • knative-eventing: A Node.js module to manage Knative Eventing instances

    Unwrapping the Serverless Framework descriptor

    The heart of the Serverless Framework deployment is the serverless.yml file that sits at the local root of the kogito-serverless-workflow-with-serverless-framework repository:

    service: newsletter
    
    frameworkVersion: '3'
    
    provider:
      name: knative
      # optional Docker Hub credentials you need if you're using local Dockerfiles as function handlers
      docker:
        username: ${env:DOCKER_HUB_USERNAME}
        password: ${env:DOCKER_HUB_PASSWORD}
    functions:
      event-display:
        handler: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display@sha256:a214514d6ba674d7393ec8448dd272472b2956207acb3f83152d3071f0ab1911
        # autoscaler field is managed by knative provider
        # Just add any autoscaling related annotation and it will be propagated to the deployed Service and Revision
        # The plugin automatically adds the 'autoscaling.knative.dev/' prefix to the annotation name
        autoscaler:
          min-scale: 1
          max-scale: 2
        events:
          - custom:
              name: new.subscription.2.event-display
              filter:
                attributes:
                  type: new.subscription
          - custom:
              name: confirm.subscription.2.event-display
              filter:
                attributes:
                  type: confirm.subscription
      subscription-service:
        handler: Dockerfile.jvm
        context: ./subscription-service
      subscription-flow:
        handler: Dockerfile.jvm
        context: ./subscription-flow
        events:
          - custom:
              filter:
                attributes:
                  type: confirm.subscription
          - sinkBinding: {}
    plugins:
      - serverless-knative

    To replicate the architecture of the original example, this deployment includes the functions listed in the following sections (the equivalents of the Knative Service resources).

    event-display

    This is an event logger application implemented with a prebuilt image from the Google Cloud Container Registry. The image is configured with a minimum of one instance to simplify logging activity, and has two custom events that are mapped onto two Knative Trigger instances.

    subscription-service

    This is the service running the original subscription-service application. The original source code was copied from the Kogito Examples repository under the subscription-service folder, to show the option to locally build an application and deploy the serverless service using the Serverless Framework CLI.

    The Dockerfile.jvm file defined by the handler property builds the Quarkus application and injects the binding properties to connect to the newsletter-postgres database:

    ENV POSTGRES_PASSWORD=cGFzcwo=
    ENV POSTGRES_HOST=newsletter-postgres.newsletter-subscription-db

    subscription-flow

    This function runs the subscription-flow image that you previously built, but with overridden properties to locate the newsletter-postgres service:

    FROM quay.io/dmartino/serverless-workflow-newsletter-subscription-flow:1.25.0.Final
    
    ENV SUBSCRIPTION_API_URL=http://newsletter-subscription-service.sls-newsletter-dev.svc.cluster.local
    ENV POSTGRES_HOST=newsletter-postgres.newsletter-subscription-db

    This serverless function is configured with one custom event, mapped to a Knative Trigger instance, and one sinkBinding event that generates the Knative SinkBinding to connect the Knative Service with the default Knative Broker. The default Knative Broker is automatically created by the eventing.knative.dev/injection annotation attached to the Knative Trigger instances.

    Deploying the application with the Serverless Framework

    The first step is to build the subscription-service application:

    $ cd subscription-service
    $ mvn clean package

    The following instructions assume that you have already installed the serverless CLI, and set the environment variables DOCKER_HUB_USERNAME and DOCKER_HUB_PASSWORD to define the access credentials to the Docker Hub repository. Now deployment is just a matter of running the serverless deploy command:

    $ serverless deploy

    The info command returns the deployment status of your application:

    $ serverless info
    ...
    Service Information
    service: newsletter
    namespace: sls-newsletter-dev
    
    Deployed functions
    event-display:
      - url: https://newsletter-event-display-sls-newsletter-dev.DOMAIN
      - custom
      - custom
    subscription-service:
      - url: https://newsletter-subscription-service-sls-newsletter-dev.DOMAIN
    subscription-flow:
      - url: https://newsletter-subscription-flow-sls-newsletter-dev.DOMAIN
      - custom
      - sinkBinding
    

    Validating the applications

    Run the applications using the default browser by executing the following:

    $ open -t $(oc get ksvc newsletter-subscription-flow -n sls-newsletter-dev -ojsonpath='{.status.url}{"\n"}')
    $ open -t $(oc get ksvc newsletter-subscription-service -n sls-newsletter-dev -ojsonpath='{.status.url}{"\n"}')

    Now you can monitor the CloudEvents events through the logs of the event-display pod:

    $ oc logs -l serving.knative.dev/service=newsletter-event-display -f -n sls-newsletter-dev -c user-container

    Serverless Framework supports cloud deployments

    By using the Serverless Framework software, we successfully deployed a serverless application on Red Hat OpenShift, using Knative as the serverless framework.

    The default implementation of the Knative Cloud Provider is missing some features and is not compatible with the Red Hat OpenShift Serverless Operator, so a patched implementation was used for the purposes of this article.

    The application is defined using the Kogito implementation of the CNCF Serverless Workflow specification, a DSL-based model that targets the serverless technology domain.

    Serverless Framework claims to be a cloud-agnostic tool, so nothing prevents us from extending the exercise in the future and adapting this deployment model to run on another cloud platform such as AWS or Azure.

    For more information, please read the blog posting Orchestrating Events with Knative and Kogito.

    Last updated: March 18, 2024

    Recent Posts

    • How to build a Model-as-a-Service platform

    • How Quarkus works with OpenTelemetry on OpenShift

    • Our top 10 articles of 2025 (so far)

    • The benefits of auto-merging GitHub and GitLab repositories

    • Supercharging AI isolation: microVMs with RamaLama & libkrun

    What’s up next?

    knative cookbook

    Enterprise developers face several challenges when it comes to building serverless applications, such as integrating applications and building container images from source. With more than 60 practical recipes, the Knative Cookbook helps you solve these issues with Knative–the first serverless platform natively designed for Kubernetes.

    Get the free e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue