使用Kogito Operator在Kubernetes上部署自定义Kogito服务

本文介绍了如何借助Kogito Operator逐步在Kubernetes集群中部署自定义的Kogito业务服务。Kogito提供了一种方式,让开发者能将复杂的业务流程和决策规则整合,并转化为可在容器环境中运行的微服务。
摘要由CSDN通过智能技术生成

The Kogito documentation states that “Kogito is a cloud-native business automation technology for building cloud-ready business applications”. In other words, a developer toolkit to create a custom business automation application targeting cloud environments.

Kogito文档指出:“ Kogito是一种用于构建云就绪业务应用程序的云原生业务自动化技术”。 换句话说,开发人员工具包可创建针对云环境的自定义业务自动化应用程序。

Kogito enables a developer to have a business process integrated with complex business decisions and rules. This process is converted into a microservice that can be deployed on a containerized environment, such as Kubernetes.

Kogito使开发人员能够将业务流程与复杂的业务决策和规则集成在一起。 该过程将转换为可在容器化环境(例如Kubernetes)上部署的微服务。

In the following sections you’ll learn step by step how you can deploy a custom Kogito service in a Kubernetes cluster using the Kogito Operator.

在以下各节中,您将逐步学习如何使用Kogito Operator在Kubernetes集群中部署自定义Kogito服务。

入门 (Getting Started)

To get started deploying your first custom Kogito service on Kubernetes you will need:

要开始在Kubernetes上部署您的第一个自定义Kogito服务,您需要:

  1. A Kubernetes cluster with cluster admin rights on it (minikube is recommended). You’ll need cluster admin rights because you are going to install new Kubernetes types in the cluster

    具有集群管理权限的Kubernetes集群(建议使用minikube )。 您将需要集群管理员权限,因为您将在集群中安装新的Kubernetes类型

  2. The latest Kogito Operator. The latest released version is available at the Github page

    最新的Kogito运算符。 最新的发行版本可以在Github页面上找到

  3. kubectl installed in your local machine

    安装在本地计算机上的kubectl

  4. Java 11, git (latest), maven (3.6.x) and podman (or docker) installed locally

    本地安装的Java 11,git(最新),maven(3.6.x)和podman (或docker )

TIP: If you’re concerned about the resources consumed by the minikube instance, for this tutorial I used an instance with 2 CPUs and 4GB RAM.

提示:如果您担心minikube实例消耗的资源,那么在本教程中,我使用了一个具有2个CPU和4GB RAM的实例。

In the Kogito Examples repository, you will find a lot of examples and use cases to get started with Kogito. To keep things simple, we will deploy the Process with Business Rules on Quarkus example. In this example, our business process will evaluate whether we need a special handling for children or not. To express the process we use the BPMN specification:

Kogito范例存储库中 ,您会找到很多示例和用例,以开始使用Kogito。 为简单起见 ,我们将在Quarkus示例中部署带有业务规则流程 。 在此示例中,我们的业务流程将评估我们是否需要对儿童进行特殊处理。 为了表示该过程,我们使用BPMN规范

Image for post
Simple Business Process that we will deploy on Kubernetes
我们将在Kubernetes上部署的简单业务流程

Kogito offers a VSCode plugin to author BPMN diagrams. This same editor can also be used online, try it out by clicking here to view and edit the above diagram live!

Kogito提供了一个VSCode插件来编写BPMN图。 该编辑器也可以在线使用, 请单击此处进行试用,以实时查看和编辑以上图表!

The nicest thing about BPMN is that you can use the same language to talk to business and IT personas. Plus, this diagram you are working with is about to be transformed into a microservice running on top of Kubernetes.

BPMN最好的事​​情是您可以使用相同的语言与业务和IT角色交谈。 另外,您正在使用的该图将转换为在Kubernetes上运行的微服务。

The image below illustrates the overall process since the creation of a new project to its deployment.

下图显示了自创建新项目以来的总体过程。

Image for post
Developer flow for deploying a Kogito service on Kubernetes
在Kubernetes上部署Kogito服务的开发人员流程

As a developer, you will create a new Java project having custom business rules, decisions or processes, then build and try it locally before deploying it into a Kubernetes cluster.

作为开发人员,您将创建一个具有自定义业务规则,决策或流程的新Java项目,然后在将其部署到Kubernetes集群之前在本地进行构建和尝试。

On Kubernetes, your custom Kogito service will be just one more microservice in your architecture, exposing the domain through REST API and well documented with Swagger. Other services won’t even be aware of your internal implementation since no Kogito API internals are exposed. Domain data is the only thing that matters here.

在Kubernetes上,您的自定义Kogito服务将是您体系结构中的又一个微服务,它通过REST API公开了该域,并通过Swagger进行了详细记录。 其他服务甚至不会意识到您的内部实现,因为没有公开Kogito API内部。 域数据是唯一重要的事情

在本地尝试Kogito服务 (Trying the Kogito service locally)

The first step to try the example is to clone the Kogito Examples’s project and to run the target project with the Quarkus Maven plugin. Execute the commands below, and notice the command will keep on running:

尝试该示例的第一步是克隆Kogito Examples的项目,并使用Quarkus Maven插件运行目标项目。 执行以下命令,并注意该命令将继续运行:

TIP: This example is using Quarkus as the target runtime, but SpringBoot is also an option to build Kogito services.

提示:此示例使用 Quarkus 作为目标运行时,但是 SpringBoot 也是构建Kogito服务的一种选择。

After running the above command, open a new terminal and start a new instance of the process by making a request to the “persons” endpoint:

运行上述命令后,打开一个新终端并通过向“ person ”端点发出请求来启动该流程的新实例:

TIP: run it on a different terminal since the Quarkus maven plugin will be in the foreground.

提示:由于Quarkus maven插件位于前台,因此请在其他终端上运行它。

To play around with the endpoints via the Swagger interface, go to http://localhost:8080/swagger-ui/. If you need more use cases of this service (such as how to retrieve a pending task), please refer to the example page.

要通过Swagger界面使用端点,请访问http:// localhost:8080 / swagger-ui / 。 如果您需要此服务的更多用例(例如如何检索待处理的任务),请参阅示例页面

Notice that every generated endpoint only contains information about the domain data, in other words, it does not have Kogito specific APIs exposed.

请注意,每个生成的端点仅包含有关域数据的信息,也就是说,它没有公开Kogito特定的API。

Before heading to the next step, stop the running instance of Quarkus to release the 8080 port.

在继续下一步之前,请停止正在运行的Quarkus实例以释放8080端口。

构建Kogito服务映像 (Building the Kogito service Image)

Having tried the custom service locally, it’s time to deploy it in your Kubernetes cluster. For this to work, you will have to build the package and the image locally and push it to a third party registry such as Quay.

在本地尝试过自定义服务后,是时候将其部署到Kubernetes集群中了。 为此,您将必须在本地构建软件包和映像,并将其推送到第三方注册表(例如Quay)。

To build the package, just run this command: mvn clean package

要构建软件包,只需运行以下命令: mvn clean package

Packaged files will then be available into the “target” folder.

然后,打包的文件将位于“目标”文件夹中。

Then to build the image, use the following Dockerfile as reference:

然后要构建映像,请使用以下Dockerfile作为参考:

Copy the content above into a Dockerfile file and add it to the project’s root (process-business-rules-quarkus). This Dockerfile is based on a special image offered by the Kogito project, and it has all the binaries and scripts needed by a custom Kogito service built with Quarkus to run. To build the image, execute the following command in the project’s root directory:

将以上内容复制到Dockerfile文件中,并将其添加到项目的根目录( process-business-rules-quarkus )。 该Dockerfile基于Kogito项目提供特殊映像 ,并且具有运行Quarkus的自定义Kogito服务所需的所有二进制文件和脚本。 要生成映像,请在项目的根目录中执行以下命令:

$ podman build — tag quay.io/<yournamespace>/process-business-rules-quarkus:latest .

Remember to update the yournamespace tag with your Quay.io username!

请记住使用Quay.io用户名更新yournamespace标签!

After building the image you can run it locally:

构建映像后,您可以在本地运行它:

$ podman run — rm -it -p 8080:8080 quay.io/<yournamespace>/process-business-rules-quarkus:latest

TIP: Don’t forget to stop the Quarkus application that you were testing before, since the ports could clash.

提示:不要忘记停止之前正在测试的Quarkus应用程序,因为端口可能会发生冲突。

You can do the same requests you’ve made so far running the example locally with the Quarkus plugin. Since we’re mapping the same port used by the service on the host machine, all the requests to localhostshould work.

到目前为止,您可以使用Quarkus插件在本地运行示例,以进行相同的请求。 由于我们正在映射主机上服务所使用的同一端口,因此对localhost所有请求均应正常工作。

After checking that the image is working, we can push it to Quay:

检查图像是否正常后,我们可以将其推入Quay:

$ podman push quay.io/<yournamespace>/process-business-rules-quarkus:latest

Once the image has been pushed to the registry, make sure that it is available publicly. Some Quay accounts create new tags in private mode by default.

将映像推送到注册表后,请确保该映像可公开使用。 默认情况下,某些Quay帐户以私有模式创建新标签。

使用Kogito Operator进行部署 (Deploying with Kogito Operator)

Here comes the fun part.

这里是有趣的部分。

Having built the image, we can use the Kogito Operator to deploy it in the Kubernetes cluster. Assuming that you’ve installed and started the minikube locally (or you have cluster admin access to a remote Kubernetes cluster), let’s first install the operator.

构建完映像后,我们可以使用Kogito Operator将其部署在Kubernetes集群中。 假设您已经在本地安装并启动了minikube(或者您具有对远程Kubernetes集群的集群管理员访问权限),那么让我们首先安装操作员。

安装Kogito操作员 (Installing the Kogito Operator)

To install the Kogito Operator in your cluster, you can download the latest source code of the Kogito Operator and use our installation script:

要在您的集群中安装Kogito Operator,您可以下载Kogito Operator的最新源代码并使用我们的安装脚本:

You should see the operator pod running in the namespace by executing:

通过执行以下操作,您应该看到操作员窗格在名称空间中运行:

If it is the first time you deploy the operator it could take a while to Kubernetes download and start the operator pod.

如果这是您首次部署操作员,则可能需要一段时间才能下载并启动Kubernetes。

Alternatively, you can use OLM to install the operator in your cluster. If you want to give it a try, you can follow the instructions listed in the Kogito OperatorHub page.

或者,您可以使用OLM在群集中安装操作员。 如果想尝试一下,可以按照Kogito OperatorHub页面中列出的说明进行操作

部署Kogito服务 (Deploying the Kogito service)

To deploy the Kogito service you’ll have to create a Kubernetes custom resource KogitoRuntime and deploy it in the namespace which you’ve installed the operator:

要部署Kogito服务,您必须创建一个Kubernetes自定义资源KogitoRuntime并将其部署在您已安装操作员的名称空间中:

After a few seconds, you should be able to access the deployed service.

几秒钟后,您应该能够访问已部署的服务。

Try fetching it with:

尝试通过以下方式获取它:

使用Ingress公开Kogito服务 (Exposing the Kogito service with an Ingress)

If you’re using Minikube, you can expose the service using an NGINX Ingress, to achieve that, follow the instructions in the Minikube documentation explaining how to expose a service. Then, create a new Ingress using the following example:

如果您使用的是Minikube,则可以使用NGINX Ingress公开该服务,为此,请按照Minikube 文档中的说明说明如何公开服务。 然后,使用以下示例创建一个新的Ingress:

You need to update your hosts file as explained in the Minikube documentation to be able to access the service through http://kogito-example.com URL.

您需要按照Minikube 文档中的说明更新hosts文件,才能通过http://kogito-example.com URL访问该服务。

After updating the hosts file you can play around with the application endpoints using the same commands you used before:

更新hosts文件后,您可以使用之前使用的相同命令来处理应用程序端点:

结论 (Conclusion)

In this tutorial you learned how to deploy a custom Kogito service in a Kubernetes cluster using the Kogito Operator. A Kogito service plays a crucial role in a microservice architecture that relies on complex business processes and decisions, abstracting the inner business requirements into standards, exposing only the domain data to other services.

在本教程中,您学习了如何使用Kogito Operator在Kubernetes集群中部署自定义Kogito服务。 Kogito服务在依赖复杂业务流程和决策,将内部业务需求抽象为标准,仅将域数据公开给其他服务的微服务体系结构中起着至关重要的作用。

There are a lot of examples in the Kogito Examples project structure, which you may try to deploy on Kubernetes using this tutorial as a reference.

Kogito示例项目结构中有很多示例,您可以尝试使用本教程作为参考在Kubernetes上进行部署。

In the next tutorial, you will approach how to deploy in Kubernetes a custom Kogito service that consumes and publishes events using Kafka. Stay tuned!

在下一个教程中,您将介绍如何在Kubernetes中部署自定义的Kogito服务,该服务使用Kafka使用和发布事件。 敬请关注!

翻译自: https://medium.com/kie-foundation/deploying-a-custom-kogito-service-on-kubernetes-with-kogito-operator-be031a2fba94

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值