10.3. 使用自定义镜像构建和 OpenShift Web 控制台在 OpenShift 上部署红帽构建 Kogito 微服务
您可以使用自定义镜像构建作为在 OpenShift 中构建和部署红帽构建红帽构建的替代选择。
操作器使用以下自定义资源来部署域特定的微服务(您开发的微服务):
-
KogitoRuntime启动运行时镜像,并根据您的要求进行配置。
先决条件
- 安装了 RHPAM Kogito Operator。
-
您可以使用必要的权限访问 OpenShift Web 控制台,以创建和编辑
KogitoRuntime。 (仅限红帽构建的 Quarkus)项目的
pom.xml文件,包含以下对quarkus-smallrye-health扩展名的依赖项。此扩展支持 OpenShift 上红帽构建 Quarkus 项目所需的 存活度和就绪度探测。Red Hat build of Quarkus applications on OpenShift
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-health</artifactId> </dependency>
流程
- 本地构建应用。
在项目根文件夹中创建
Containerfile,其内容如下:红帽构建的 Quarkus 应用程序的
Containerfile示例FROM registry.redhat.io/rhpam-7/rhpam-kogito-runtime-jvm-rhel8:7.11.0 ENV RUNTIME_TYPE quarkus COPY target/quarkus-app/lib/ $KOGITO_HOME/bin/lib/ COPY target/quarkus-app/*.jar $KOGITO_HOME/bin COPY target/quarkus-app/app/ $KOGITO_HOME/bin/app/ COPY target/quarkus-app/quarkus/ $KOGITO_HOME/bin/quarkus/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-
application-jar-file是应用的 JAR 文件的名称。
-
使用以下命令构建 Kogito 镜像的红帽构建:
podman build --tag <final-image-name> -f <Container-file>在上一命令中,
final-image-name是 Kogito 镜像的红帽构建的名称,Container-file是您在上一步中创建的Containerfile的名称。另外,还可使用以下命令测试构建的镜像:
podman run --rm -it -p 8080:8080 <final-image-name>使用以下命令将构建的 Kogito 镜像推送到镜像 registry:
podman push <final-image-name>-
进入 Operators
Installed Operators,再选择 RHPAM Kogito Operator。 - 要创建 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 spec: image: <final-image-name> # Kogito image name insecureImageRegistry: true # Can be omitted when image is pushed into secured registry with valid certificate使用红帽构建 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: image: <final-image-name> # Kogito image name insecureImageRegistry: true # Can be omitted when image is pushed into secured registry with valid certificate runtime: springboot定义应用程序数据后,单击 Create 以生成红帽构建 Kogito 微服务。
您的应用在红帽构建的 Kogito 微服务页面中列出。您可以选择应用程序名称来查看或修改应用程序设置以及 YAML 文件的内容。
-
应用程序构建完成后,进入 Workloads
Deployments 以查看应用程序部署、pod 状态和其他详情。 部署红帽构建 Kogito 微服务后,在 Web 控制台的左侧菜单中,前往 Networking
Routes 来查看对部署的应用程序的访问链接。 您可以选择应用程序名称来查看或修改路由设置。
通过应用程序路由,您可以根据需要将红帽构建 Kogito 微服务与业务自动化解决方案集成。