10.3. 使用自定义镜像构建和 OpenShift Web 控制台在 OpenShift 上部署 Red Hat Kogito 微服务
您可以使用自定义镜像构建作为在 OpenShift 中构建和部署 Kogito 微服务的替代选择。
Operator 使用以下自定义资源来部署特定于域的微服务(您开发的微服务):
-
KogitoRuntime启动运行时镜像,并根据要求进行配置。
先决条件
- 已安装 RHPAM Kogito Operator。
-
您可以访问 OpenShift Web 控制台,具有创建并编辑
KogitoRuntime所需的权限。 (仅红帽构建的 Quarkus)项目的
pom.xml文件包含了对quarkus-smallrye-health扩展的以下依赖项。此扩展启用 OpenShift 中红帽构建 Quarkus 项目所需的 存活度和就绪度探测。在 OpenShift 中红帽构建的 Quarkus 应用程序的 SmallRye Health 依赖项
<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
流程
- 本地构建应用程序。
在项目根目录中创建
Containerfile并包含以下内容:Red Hat build of Quarkus 应用程序的
Containerfile示例Copy to Clipboard Copied! Toggle word wrap Toggle overflow Spring Boot 应用程序的
Containerfile示例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/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-file是应用的 JAR 文件的名称。
-
使用以下命令构建 Kogito 镜像的红帽构建:
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 在上一命令中,
final-image-name是 Red Hat build of Kogito 镜像,Container-file是您在上一步中创建的Containerfile的名称。另外,还可使用以下命令测试构建的镜像:
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 使用以下命令将构建的 Red Hat build of Kogito 镜像推送到镜像 registry:
podman push <final-image-name>
podman push <final-image-name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
进入 Operators
Installed Operators 并选择 RHPAM Kogito Operator。 - 要创建 Red Hat build of Kogito 微服务定义,请在 operator 页面中选择 Kogito Runtime 选项卡,然后点击 Create KogitoRuntime。
在应用窗口中,使用 Form View 或 YAML View 来配置微服务定义。
至少,定义以下示例 YAML 文件中显示的应用程序配置:
带有红帽构建的 Kogito 微服务构建的 Red Hat build 的 YAML 定义示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 带有红帽构建的 Kogito 微服务的 Spring Boot 应用程序的 YAML 定义示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 定义应用程序数据后,点 Create 生成 Red Hat build of Kogito 微服务。
您的应用程序在红帽构建的 Kogito 微服务页面中列出。您可以选择应用程序名称来查看或修改应用程序设置以及 YAML 文件的内容。
-
应用程序构建完成后,进入 Workloads
Deployments 来查看应用程序部署、pod 状态和其他详情。 部署完 Red Hat build of Kogito microservice 后,在 web 控制台的左侧菜单中,转至 Networking
Routes 以查看对部署的应用程序的访问链接。 您可以选择应用程序名称来查看或修改路由设置。
通过应用程序路由,您可以根据需要将 Kogito 微服务构建与业务自动化解决方案集成。