10.4. 使用文件构建和 OpenShift Web 控制台在 OpenShift 上部署红帽构建 Kogito 微服务
您可以从单个文件(如决策模型和符号(DMN)、Drools Rule Language (DRL)或属性文件)构建和部署红帽构建 Kogito 微服务。您可以从本地文件系统路径指定一个文件,或者只指定本地文件系统路径中的文件目录。将文件或目录上传到 OpenShift 集群时,会自动触发新的 Source-to-Image (S2I)构建。
操作器使用以下自定义资源来部署域特定的微服务(您开发的微服务):
-
KogitoBuild从文件生成应用程序,并生成运行时镜像。 -
KogitoRuntime启动运行时镜像,并根据您的要求进行配置。
先决条件
- 安装了 RHPAM Kogito Operator。
-
ocOpenShift CLI 已安装,您已登录到相关的 OpenShift 集群。有关oc安装和登录说明,请参阅 OpenShift 文档。 -
您可以使用必要的权限访问 OpenShift Web 控制台,以创建和编辑
KogitoBuild和KogitoRuntime。
流程
-
进入 Operators
Installed Operators,再选择 RHPAM Kogito Operator。 - 要创建 Kogito 构建定义的红帽构建,请在 operator 页面中选择 Kogito Build 选项卡,然后点 Create KogitoBuild。
在应用程序窗口中,使用 Form View 或 YAML View 来配置构建定义。
至少,定义以下示例 YAML 文件中的应用程序配置:
使用红帽构建 Kogito 构建的红帽构建的 Quarkus 应用程序的 YAML 定义
apiVersion: rhpam.kiegroup.org/v1 # Red Hat build of Kogito API for this service kind: KogitoBuild # Application type metadata: name: example-quarkus # Application name spec: type: LocalSource使用 Red Hat build of Kogito build 的 Spring Boot 应用程序的 YAML 定义示例
apiVersion: rhpam.kiegroup.org/v1 # Red Hat build of Kogito API for this service kind: KogitoBuild # Application type metadata: name: example-springboot # Application name spec: runtime: springboot type: LocalSource注意如果您配置了内部 Maven 存储库,您可以将其用作 Maven 镜像服务,并在红帽构建的 Kogito build 定义中指定 Maven 镜像 URL,以大大缩短构建时间:
spec: mavenMirrorURL: http://nexus3-nexus.apps-crc.testing/repository/maven-public/有关内部 Maven 存储库的更多信息,请参阅 Apache Maven 文档。
定义应用程序数据后,点 Create 来生成 Kogito 构建的红帽构建。
您的应用程序 在红帽构建的 KogitoBuilds 页面中列出。您可以选择应用程序名称来查看或修改应用程序设置和 YAML 详情。
使用以下命令上传文件资产:
$ oc start-build example-quarkus-builder --from-file=<file-asset-path> -n namespace-
file-asset-path是您要上传的文件资产的路径。 -
namespace是创建KogitoBuild的命名空间。
-
- 要创建 Kogito 微服务定义的红帽构建,请在 operator 页面中选择 Kogito Runtime 选项卡,然后单击 Create KogitoRuntime。
在应用窗口中,使用 Form View 或 YAML View 来配置微服务定义。
至少,定义以下示例 YAML 文件中的应用程序配置:
红帽构建的带有 Kogito 微服务的 Quarkus 应用程序的 YAML 定义
apiVersion: rhpam.kiegroup.org/v1 # Red Hat build of Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-quarkus # Application name使用红帽构建 Kogito 微服务的 Spring Boot 应用程序的 YAML 定义示例
apiVersion: rhpam.kiegroup.org/v1 # Red Hat build of Kogito API for this microservice kind: KogitoRuntime # Application type metadata: name: example-springboot # Application name spec: runtime: springboot注意在这种情况下,应用程序是从一个文件构建的,并使用 KogitoRuntime 进行部署。您必须确保在
KogitoBuild和KogitoRuntime中应用程序名称相同。定义应用程序数据后,单击 Create 以生成红帽构建 Kogito 微服务。
您的应用在红帽构建的 Kogito 微服务页面中列出。您可以选择应用程序名称来查看或修改应用程序设置以及 YAML 文件的内容。
在 Web 控制台的左侧菜单中,进入 Builds
Builds 来查看应用程序构建的状态。 您可以选择特定的构建来查看构建详情。
注意对于您为 OpenShift 部署创建的 Kogito 微服务的每个红帽构建,会在 web 控制台中的 Builds 页面中生成并列出两个构建:传统的运行时构建以及带有后缀
-builder的 Source-to-Image (S2I)构建。S2I 机制在 OpenShift 构建中构建应用,然后将构建的应用传递到下一 OpenShift 构建,以打包到运行时容器镜像。-
应用程序构建完成后,进入 Workloads
Deployments 以查看应用程序部署、pod 状态和其他详情。 部署红帽构建 Kogito 微服务后,在 Web 控制台的左侧菜单中,前往 Networking
Routes 来查看对部署的应用程序的访问链接。 您可以选择应用程序名称来查看或修改路由设置。
通过应用程序路由,您可以根据需要将红帽构建 Kogito 微服务与业务自动化解决方案集成。