Chapter 21. Deploying Kogito microservices on Red Hat OpenShift Container Platform
As a business rules developer, you can deploy Kogito microservices on Red Hat OpenShift Container Platform for cloud implementation. The Red Hat Decision Manager Kogito Operator automates many of the deployment steps for you or guides you through the deployment process.
Prerequisites
- Red Hat OpenShift Container Platform 4.6 or 4.7 is installed.
- The OpenShift project for the deployment is created.
21.1. Kogito on Red Hat OpenShift Container Platform Copy linkLink copied to clipboard!
You can deploy Kogito microservices on Red Hat OpenShift Container Platform for cloud implementation. In this architecture, Kogito microservices are deployed as OpenShift pods that you can scale up and down individually to provide as few or as many containers as required for a particular service.
To help you deploy your Kogito microservices on OpenShift, Red Hat Decision Manager provides Red Hat Process Automation Manager Kogito Operator. This operator guides you through the deployment process. The operator is based on the Operator SDK and automates many of the deployment steps for you. For example, when you provide the operator with a link to the Git repository that contains your application, the operator automatically configures the components required to build your project from source and deploys the resulting services.
To install the Red Hat Process Automation Manager Kogito Operator in OpenShift web console, go to Operators
21.2. OpenShift deployment options with the Red Hat Decision Manager Kogito Operator Copy linkLink copied to clipboard!
After you create your Kogito microservices as part of a business application, you can use the Red Hat OpenShift Container Platform web console to deploy your microservices. The Red Hat Decision Manager Kogito Operator page in the OpenShift web console guides you through the deployment process.
The Red Hat Process Automation Manager Kogito Operator supports the following options for building and deploying Kogito microservices on Red Hat OpenShift Container Platform:
- Git source build and deployment
- Binary build and deployment
- Custom image build and deployment
- File build and deployment
21.2.1. Deploying Kogito microservices on OpenShift using Git source build and OpenShift web console Copy linkLink copied to clipboard!
The Red Hat Process Automation Manager Kogito Operator uses the following custom resources to deploy domain-specific microservices (the microservices that you develop):
-
KogitoBuildbuilds an application using the Git URL or other sources and produces a runtime image. -
KogitoRuntimestarts the runtime image and configures it as per your requirements.
In most use cases, you can use the standard runtime build and deployment method to deploy Kogito microservices on OpenShift from a Git repository source, as shown in the following procedure.
If you are developing or testing your Kogito microservice locally, you can use the binary build, custom image build, or file build option to build and deploy from a local source instead of from a Git repository.
Prerequisites
- The Red Hat Process Automation Manager Kogito Operator is installed.
- The application with your Kogito microservices is in a Git repository that is reachable from your OpenShift environment.
-
You have access to the OpenShift web console with the necessary permissions to create and edit
KogitoBuildandKogitoRuntime. (Quarkus only) The
pom.xmlfile of your project contains the following dependency for the Quarkussmallrye-healthextension. This extension enables the liveness and readiness probes that are required for Quarkus-based projects on OpenShift.SmallRye Health dependency for Quarkus applications on OpenShift
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
-
Go to Operators
Installed Operators and select RHPAM Kogito Operator. - To create the Kogito build definition, on the operator page, select the Kogito Build tab and click Create KogitoBuild.
In the application window, use Form View or YAML View to configure the build definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito build
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito build
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you configured an internal Maven repository, you can use it as a Maven mirror service and specify the Maven mirror URL in your Kogito build definition to shorten build time substantially:
spec: mavenMirrorURL: http://nexus3-nexus.apps-crc.testing/repository/maven-public/
spec: mavenMirrorURL: http://nexus3-nexus.apps-crc.testing/repository/maven-public/Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about internal Maven repositories, see the Apache Maven documentation.
After you define your application data, click Create to generate the Kogito build.
Your application is listed in the KogitoBuilds page. You can select the application name to view or modify application settings and YAML details.
- To create the Kogito microservice definition, on the operator page, select the Kogito Runtime tab and click Create KogitoRuntime.
In the application window, use Form View or YAML View to configure the microservice definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito microservices
apiVersion: rhpam.kiegroup.org/v1 # Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application name
apiVersion: rhpam.kiegroup.org/v1 # Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito microservices
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIn this case, the application is built from Git and deployed using KogitoRuntime. You must ensure that the application name is same in
KogitoBuildandKogitoRuntime.After you define your application data, click Create to generate the Kogito microservice.
Your application is listed in the Kogito microservice page. You can select the application name to view or modify application settings and the contents of the YAML file.
In the left menu of the web console, go to Builds
Builds to view the status of your application build. You can select a specific build to view build details.
NoteFor every Kogito microservice that you create for OpenShift deployment, two builds are generated and listed in the Builds page in the web console: a traditional runtime build and a Source-to-Image (S2I) build with the suffix
-builder. The S2I mechanism builds the application in an OpenShift build and then passes the built application to the next OpenShift build to be packaged into the runtime container image. The Kogito S2I build configuration also enables you to build the project directly from a Git repository on the OpenShift platform.-
After the application build is complete, go to Workloads
Deployments to view the application deployments, pod status, and other details. After your Kogito microservice is deployed, in the left menu of the web console, go to Networking
Routes to view the access link to the deployed application. You can select the application name to view or modify route settings.
With the application route, you can integrate your Kogito microservices with your business automation solutions as needed.
21.2.2. Deploying Kogito microservices on OpenShift using binary build and OpenShift web console Copy linkLink copied to clipboard!
OpenShift builds can require extensive amounts of time. As a faster alternative for building and deploying your Kogito microservices on OpenShift, you can use a binary build.
The operator uses the following custom resources to deploy domain-specific microservices (the microservices that you develop):
-
KogitoBuildprocesses an uploaded application and produces a runtime image. -
KogitoRuntimestarts the runtime image and configures it as per your requirements.
Prerequisites
- The Red Hat Process Automation Manager Kogito Operator is installed.
-
The
ocOpenShift CLI is installed and you are logged in to the relevant OpenShift cluster. Forocinstallation and login instructions, see the OpenShift documentation. -
You have access to the OpenShift web console with the necessary permissions to create and edit
KogitoBuildandKogitoRuntime. (Quarkus only) The
pom.xmlfile of your project contains the following dependency for the Quarkussmallrye-healthextension. This extension enables the liveness and readiness probes that are required for Quarkus-based projects on OpenShift.SmallRye Health dependency for Quarkus applications on OpenShift
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Build an application locally.
-
Go to Operators
Installed Operators and select RHPAM Kogito Operator. - To create the Kogito build definition, on the operator page, select the Kogito Build tab and click Create KogitoBuild.
In the application window, use Form View or YAML View to configure the build definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito build
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito build
Copy to Clipboard Copied! Toggle word wrap Toggle overflow After you define your application data, click Create to generate the Kogito build.
Your application is listed in the KogitoBuilds page. You can select the application name to view or modify application settings and YAML details.
Upload the built binary using the following command:
oc start-build example-quarkus --from-dir=target/ -n namespace
$ oc start-build example-quarkus --from-dir=target/ -n namespaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
from-diris equals to thetargetfolder path of the built application. -
namespaceis the namespace whereKogitoBuildis created.
-
- To create the Kogito microservice definition, on the operator page, select the Kogito Runtime tab and click Create KogitoRuntime.
In the application window, use Form View or YAML View to configure the microservice definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito microservices
apiVersion: rhpam.kiegroup.org/v1 # Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application name
apiVersion: rhpam.kiegroup.org/v1 # Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito microservices
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIn this case, the application is built locally and deployed using KogitoRuntime. You must ensure that the application name is same in
KogitoBuildandKogitoRuntime.After you define your application data, click Create to generate the Kogito microservice.
Your application is listed in the Kogito microservice page. You can select the application name to view or modify application settings and the contents of the YAML file.
In the left menu of the web console, go to Builds
Builds to view the status of your application build. You can select a specific build to view build details.
-
After the application build is complete, go to Workloads
Deployments to view the application deployments, pod status, and other details. After your Kogito microservice is deployed, in the left menu of the web console, go to Networking
Routes to view the access link to the deployed application. You can select the application name to view or modify route settings.
With the application route, you can integrate your Kogito microservices with your business automation solutions as needed.
21.2.3. Deploying Kogito microservices on OpenShift using custom image build and OpenShift web console Copy linkLink copied to clipboard!
You can use custom image build as an alternative for building and deploying your Kogito microservices on OpenShift.
The operator uses the following custom resources to deploy domain-specific microservices (the microservices that you develop):
-
KogitoRuntimestarts the runtime image and configures it as per your requirements.
Prerequisites
- The Red Hat Process Automation Manager Kogito Operator is installed.
-
You have access to the OpenShift web console with the necessary permissions to create and edit
KogitoRuntime. (Quarkus only) The
pom.xmlfile of your project contains the following dependency for the Quarkussmallrye-healthextension. This extension enables the liveness and readiness probes that are required for Quarkus-based projects on OpenShift.SmallRye Health dependency for Quarkus applications on OpenShift
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Build an application locally.
Create
Containerfilein the project root folder with the following content:Example
Containerfilefor a Quarkus applicationCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Containerfilefor a Spring Boot applicationFROM registry.redhat.io/rhpam-7/rhpam-kogito-runtime-jvm-rhel8:7.11.0 ENV RUNTIME_TYPE springboot COPY target/<application-jar-file> $KOGITO_HOME/bin
FROM registry.redhat.io/rhpam-7/rhpam-kogito-runtime-jvm-rhel8:7.11.0 ENV RUNTIME_TYPE springboot COPY target/<application-jar-file> $KOGITO_HOME/binCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
application-jar-fileis the name of the JAR file of the application.
-
Build the Kogito image using the following command:
podman build --tag <final-image-name> -f <Container-file>
podman build --tag <final-image-name> -f <Container-file>Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the previous command,
final-image-nameis the name of the Kogito image andContainer-fileis name of theContainerfilethat you created in the previous step.Optionally, test the built image using the following command:
podman run --rm -it -p 8080:8080 <final-image-name>
podman run --rm -it -p 8080:8080 <final-image-name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push the built Kogito image to an image registry using the following command:
podman push <final-image-name>
podman push <final-image-name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Go to Operators
Installed Operators and select RHPAM Kogito Operator. - To create the Kogito microservice definition, on the operator page, select the Kogito Runtime tab and click Create KogitoRuntime.
In the application window, use Form View or YAML View to configure the microservice definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito microservices
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito microservices
Copy to Clipboard Copied! Toggle word wrap Toggle overflow After you define your application data, click Create to generate the Kogito microservice.
Your application is listed in the Kogito microservice page. You can select the application name to view or modify application settings and the contents of the YAML file.
-
After the application build is complete, go to Workloads
Deployments to view the application deployments, pod status, and other details. After your Kogito microservice is deployed, in the left menu of the web console, go to Networking
Routes to view the access link to the deployed application. You can select the application name to view or modify route settings.
With the application route, you can integrate your Kogito microservices with your business automation solutions as needed.
21.2.4. Deploying Kogito microservices on OpenShift using file build and OpenShift web console Copy linkLink copied to clipboard!
You can build and deploy your Kogito microservices from a single file, such as a Decision Model and Notation (DMN), Drools Rule Language (DRL), or properties file, or from a directory with multiple files. You can specify a single file from your local file system path or specify a file directory from a local file system path only. When you upload the file or directory to an OpenShift cluster, a new Source-to-Image (S2I) build is automatically triggered.
The operator uses the following custom resources to deploy domain-specific microservices (the microservices that you develop):
-
KogitoBuildgenerates an application from a file and produces a runtime image. -
KogitoRuntimestarts the runtime image and configures it as per your requirements.
Prerequisites
- The Red Hat Process Automation Manager Kogito Operator is installed.
-
The
ocOpenShift CLI is installed and you are logged in to the relevant OpenShift cluster. Forocinstallation and login instructions, see the OpenShift documentation. -
You have access to the OpenShift web console with the necessary permissions to create and edit
KogitoBuildandKogitoRuntime.
Procedure
-
Go to Operators
Installed Operators and select RHPAM Kogito Operator. - To create the Kogito build definition, on the operator page, select the Kogito Build tab and click Create KogitoBuild.
In the application window, use Form View or YAML View to configure the build definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito build
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito build
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you configured an internal Maven repository, you can use it as a Maven mirror service and specify the Maven mirror URL in your Kogito build definition to shorten build time substantially:
spec: mavenMirrorURL: http://nexus3-nexus.apps-crc.testing/repository/maven-public/
spec: mavenMirrorURL: http://nexus3-nexus.apps-crc.testing/repository/maven-public/Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information about internal Maven repositories, see the Apache Maven documentation.
After you define your application data, click Create to generate the Kogito build.
Your application is listed in the KogitoBuilds page. You can select the application name to view or modify application settings and YAML details.
Upload the file asset using the following command:
oc start-build example-quarkus-builder --from-file=<file-asset-path> -n namespace
$ oc start-build example-quarkus-builder --from-file=<file-asset-path> -n namespaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
file-asset-pathis the path of the file asset that you want to upload. -
namespaceis the namespace whereKogitoBuildis created.
-
- To create the Kogito microservice definition, on the operator page, select the Kogito Runtime tab and click Create KogitoRuntime.
In the application window, use Form View or YAML View to configure the microservice definition.
At a minimum, define the application configurations shown in the following example YAML file:
Example YAML definition for a Quarkus application with Kogito microservices
apiVersion: rhpam.kiegroup.org/v1 # Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application name
apiVersion: rhpam.kiegroup.org/v1 # Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example YAML definition for a Spring Boot application with Kogito microservices
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIn this case, the application is built from a file and deployed using KogitoRuntime. You must ensure that the application name is same in
KogitoBuildandKogitoRuntime.After you define your application data, click Create to generate the Kogito microservice.
Your application is listed in the Kogito microservice page. You can select the application name to view or modify application settings and the contents of the YAML file.
In the left menu of the web console, go to Builds
Builds to view the status of your application build. You can select a specific build to view build details.
NoteFor every Kogito microservice that you create for OpenShift deployment, two builds are generated and listed in the Builds page in the web console: a traditional runtime build and a Source-to-Image (S2I) build with the suffix
-builder. The S2I mechanism builds the application in an OpenShift build and then passes the built application to the next OpenShift build to be packaged into the runtime container image.-
After the application build is complete, go to Workloads
Deployments to view the application deployments, pod status, and other details. After your Kogito microservice is deployed, in the left menu of the web console, go to Networking
Routes to view the access link to the deployed application. You can select the application name to view or modify route settings.
With the application route, you can integrate your Kogito microservices with your business automation solutions as needed.
21.3. Probes for Kogito microservices on Red Hat OpenShift Container Platform Copy linkLink copied to clipboard!
The probes in Red Hat OpenShift Container Platform verify that an application is working or it needs to be restarted. For Kogito microservices on Quarkus and Spring Boot, probes interact with the application using an HTTP request, defaulting to the endpoints that are exposed by an extension. Therefore, to run your Kogito microservices on Red Hat OpenShift Container Platform, you must import the extensions to provide application availability information for the liveness, readiness, and startup probes.
21.3.1. Adding health check extension for Quarkus-based Kogito microservices on Red Hat OpenShift Container Platform Copy linkLink copied to clipboard!
You can add the health check extension for the Quarkus-based Kogito services on Red Hat OpenShift Container Platform.
Procedure
In a command terminal, navigate to the pom.xml file of your project and add the following dependency for the Quarkus smallrye-health extension:
SmallRye Health dependency for Quarkus applications on Red Hat OpenShift Container Platform
21.3.2. Adding health check extension for Spring Boot-based Kogito microservices on Red Hat OpenShift Container Platform Copy linkLink copied to clipboard!
You can add the health check extension for the Spring Boot-based Kogito microservices on Red Hat OpenShift Container Platform.
Procedure
In a command terminal, navigate to the pom.xml file of your project and add the following Spring Boot actuator dependency:
Spring Boot actuator dependency for Spring Boot applications on Red Hat OpenShift Container Platform
21.3.3. Setting custom probes for Kogito microservices on Red Hat OpenShift Container Platform Copy linkLink copied to clipboard!
You can also configure the custom endpoints for the liveness, readiness, and startup probes.
Procedure
-
Define the probes in the
KogitoRuntimeYAML file of your project, as shown in the following example:
Example Kogito microservice custom resource with custom probe endpoints
21.4. Red Hat Process Automation Manager Kogito Operator interaction with Prometheus and Grafana Copy linkLink copied to clipboard!
Kogito in Red Hat Decision Manager provides a monitoring-prometheus-addon add-on that enables Prometheus metrics monitoring for Kogito microservices and generates Grafana dashboards that consume the default metrics exported by the add-on. The RHPAM Kogito Operator uses the Prometheus Operator to expose the metrics from your project for Prometheus to scrape. Due to this dependency, the Prometheus Operator must be installed in the same namespace as your project.
If you want to enable the Prometheus metrics monitoring for your Kogito microservices, add the following dependency to the pom.xml file in your project, depending on the framework you are using:
Dependency for Prometheus Quarkus add-on
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>monitoring-prometheus-quarkus-addon</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>monitoring-prometheus-quarkus-addon</artifactId>
</dependency>
Dependency for Prometheus Spring Boot add-on
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>monitoring-prometheus-springboot-addon</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>monitoring-prometheus-springboot-addon</artifactId>
</dependency>
When you deploy a Kogito microservice that uses the monitoring-prometheus-addon add-on and the Prometheus Operator is installed, the Red Hat Process Automation Manager Kogito Operator creates a ServiceMonitor custom resource to expose the metrics for Prometheus, as shown in the following example:
Example ServiceMonitor resource for Prometheus
You must manually configure your Prometheus custom resource that is managed by the Prometheus Operator to select the ServiceMonitor resource:
Example Prometheus resource
After you configure your Prometheus resource with the ServiceMonitor resource, you can see the endpoint scraped by Prometheus in the Targets page in the Prometheus web console. The metrics exposed by the Red Hat Decision Manager service appear in the Graph view.
The Red Hat Process Automation Manager Kogito Operator also creates a GrafanaDashboard custom resource defined by the Grafana Operator for each of the Grafana dashboards generated by the add-on. The app label for the dashboards is the name of the deployed Kogito microservice. You must set the dashboardLabelSelector property of the Grafana custom resource according to the relevant Kogito microservice.
Example Grafana resource
21.5. Kogito microservice deployment troubleshooting Copy linkLink copied to clipboard!
Use the information in this section to troubleshoot issues that you might encounter when using the operator to deploy Kogito microservices. The following information is updated as new issues and workarounds are discovered.
- No builds are running
If you do not see any builds running nor any resources created in the relevant namespace, enter the following commands to retrieve running pods and to view the operator log for the pod:
View Kogito Operator log for a specified pod
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Verify
KogitoRuntimestatus If you create, for example,
KogitoRuntimeapplication with a non-existing image using the following YAML definition:Example YAML definition for a
KogitoRuntimeapplicationCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can verify the status of the
KogitoRuntimeapplication using theoc describe KogitoRuntime examplecommand in the bash console. When you run theoc describe KogitoRuntime examplecommand in the bash console, you receive the following output:Example
KogitoRuntimestatusCopy to Clipboard Copied! Toggle word wrap Toggle overflow At the end of the output, you can see the
KogitoRuntimestatus with a relevant message.