Building and deploying a Serverless Workflow application on Kubenetes using the Kogito Serverless Operator
This document describes how to build and deploy your workflow application using a Kubernetes cluster with the Kogito Serverless Operator. If you don’t have any cluster operational, Minikube commands are given throughout the guide.
Using the Kogito Serverless Operator, you will be able to build and deploy a Kogito Serverless Workflow application only by having a workflow definition.
If you already have a container built and pushed to a container registry and you want to deploy it on the Kubernetes cluster, then you can do it without the operator following the guide Deploying your Serverless Workflow application on Kubernetes.
The Kogito Serverless Operator is currently in Alpha version, is under active development and is at the moment supporting Serverless Workflow definitions that are using:
-
Functions
-
States
-
Switch including dataConditions
-
Inject including data with a transition
-
-
Operations including Actions containing functionRef with arguments
-
KeepActive
-
AutoRetries
-
ExpressionsLang (jq or jsonpath)
-
A workflow definition.
-
A Kubernetes cluster with admin privileges +If you haven’t got one prepare, you can use a local Minikube instance.
-
kubectl
command-line tool is installed. +Otherwise, Minikube provides it.
Prepare a Minikube instance
minikube start --cpus 4 --memory 4096 --addons registry --addons metrics-server --insecure-registry "10.0.0.0/24" --insecure-registry "localhost:5000"
To speed up the build time, you can increase CPUs and memory options so that you minikube instance will have more resources. For example, use |
If it does not work with the default driver, as known as |
minikube start [...] --driver podman
There are some issues with the |
Setup Kogito Serverless Operator
In order to have an up-and-running instance of the Kogito Serverless Operator you can use the following command:
kubectl create -f https://raw.githubusercontent.com/kiegroup/kogito-serverless-operator/v1.32.0F/operator.yaml
You can follow, then, the deployment of the Kogito Serverless Operator:
kubectl get pod -n kogito-serverless-operator-system --watch
You can also follow the operator’s log:
kubectl logs deployment/kogito-serverless-operator-controller-manager -n kogito-serverless-operator-system -f
Once the operator is running, it will watch for new custom resources (CR) so that you can prepare your environment to be ready to build a new Serverless Workflow application based on the definitions you will send to the operator.
Preparing for the build
You should follow these steps to create a container that you can deploy as a service on Kubernetes.
Create a namespace for the building phase
Let’s create a new namespace that will hold all the resources that we (or the operator) will create (pods, deployments, services, secretes, config map, and Custom Resources) in this guide.
kubectl create namespace kogito-workflows
Create a secret for the container registry authentication
kubectl create secret docker-registry regcred --docker-server=<registry_url> --docker-username=<registry_username> --docker-password=<registry_password> --docker-email=<registry_email> -n kogito-workflows
or you can directly import your local docker config into your the Kubernetes cluster:
kubectl create secret generic regcred --from-file=.dockerconfigjson=${HOME}/.docker/config.json --type=kubernetes.io/dockerconfigjson -n kogito-workflows
Create a Kogito Serverless Platform containing the configuration (i.e. registry address, secret) for building your workflows
The Kogito Serverless Platform CR is the resource used to control the behavior of the Kogito Serverless Operator. It defines the behavior of all Custom Resources (Workflow and Build) in the given namespace.
Since the Kogito Serverless Operator is installed in global mode, you will need to specify a Kogito Serverless Platform CR in each namespace where you want the operator to be executed.
You can find a basic Kogito Serverless Platform CR example in the config/samples
folder that you can simply apply to configure your operator.
kubectl apply -f https://raw.githubusercontent.com/kiegroup/kogito-serverless-operator/v1.32.0/config/samples/sw.kogito_v1alpha08_kogitoserverlessplatform.yaml -n kogito-workflows
Note: In this Custom Resource, spec.platform.registry.secret is the name of the secret you created just before.
You can also update "on-the-fly" the Kogito Serverless Platform CR registry field with this command (change <YOUR_REGISTRY>) Create a Kogito Serverless Platform CR with a specific registry
In order to retrieve the Cluster IP address of Minikube’s internal registry to configure your platform, you can use the following command: Retrieve Minikube registry internal IP
|
Build and deploy your Serverless Workflow application
You can now send your Kogito Serverless Workflow Custom Resource to the operator which includes the Serverless Workflow definition.
You can find a basic Kogito Serverless Workflow Custom Resource in the config/samples
folder that is defining the Kogito Serverless Workflow Greeting example.
kubectl apply -f https://raw.githubusercontent.com/kiegroup/kogito-serverless-operator/v1.32.0/config/samples/sw.kogito_v1alpha08_kogitoserverlessworkflow.yaml -n kogito-workflows
You can check the logs of the build of your workflow via:
kubectl logs kogito-greeting-builder -n kogito-workflows
The final pushed image must be printed into the logs at the end of the build.
Check the Kogito Serverless Workflow application is running
In order to check that the Kogito Serverless Workflow Greeting application is up and running, you can try to perform a test HTTP call, from the greeting pod.
kubectl patch svc greeting -n kogito-workflows -p '{"spec": {"type": "NodePort"}}'
GREETING_SVC=$(minikube service greeting -n kogito-workflows --url)
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name": "John", "language": "English"}' $GREETING_SVC/greeting
If everything is working well you should receive a response like this:
{"id":"b5fbfaa3-b125-4e6c-9311-fe5a3577efdd","workflowdata":{"name":"John","language":"English","greeting":"Hello from JSON Workflow, "}}