使用 Code Ready Studio 在 OpenShift 上使用 Fuse 7

x33g5p2x  于2022-09-28 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(372)

OpenShift 上的 Red Hat Fuse 让您可以在 OpenShift Container Platform 上部署 Fuse 应用程序。在本教程中,我们将介绍如何使用 Code Ready Studio 在 OpenShift 上部署 Fuse 应用程序以快速生成示例应用程序。

先决条件:

您需要在 OpenShift 4.x 服务器上安装 Fuse Imagestreams 和 Templates。 ImageStrams 是一个 OpenShift API 对象,表示相关图像的单个虚拟视图。

安装图片流和模板可以参考脚本:https://github.com/rahmed-rh/fuse_on_OCP_7.5/blob/master/scripts/install_fis_7.5.sh

(请注意,要安装 Fuse Imagestreams 和 Templates,您必须具有 OpenShift 项目的管理员角色。)

创建您的 Fuse 7 应用程序

启动 Code Ready Studio 并选择创建一个新的 Fuse Integration 应用程序:

接下来,选择目标Environment

当我们想在 OpenShift 上部署应用程序时,请检查 Kubernetes/Openshift。

然后您可以在三个不同的运行时之间进行选择:

  • Spring Boot 应用程序: 将 Fuse 集成项目部署为 Spring Boot 应用程序
  • Karaf/Fuse:部署基于 OSGI 的应用程序
  • WildFly/EAP:将应用程序部署在 WildFly/EAP 环境之上

该项目将为您创建。这是您项目的树视图,其中仅包含一个 Spring Application 类和一个包含 Camel 上下文定义的 camel-context.xml 文件:

src └── main     ├── fabric8     │   └── deployment.yml     ├── java     │   └── org     │       └── mycompany     │           └── Application.java     └── resources         ├── application.properties         ├── logback.xml         └── spring             └── camel-context.xml

这是使用设计器的路线视图:

我需要应用于 pom.xml 的唯一更改与 fabric8 Maven 插件有关。事实上,使用项目中包含的 fabric8 插件版本,我面临以下错误:

[ERROR] Failed to execute goal org.jboss.redhat-fuse:fabric8-maven-plugin:7.4.0.fuse-740036-redhat-00002:build (default) on project fuse-spring-boot: Failed to execute the build: Unable to build the image using the OpenShift build service: OpenShift Build fuse-spring-boot-s2i-1: Failed: GenericBuildFailed -> [Help 1]

只需将 openshift 配置文件中包含的插件切换为以下插件:

<profile>    <id>openshift</id>    <build>       <plugins>          <plugin>             <groupId>io.fabric8</groupId>             <artifactId>fabric8-maven-plugin</artifactId>             <version>4.4.1</version>             <executions>                <execution>                   <goals>                      <goal>resource</goal>                      <goal>build</goal>                   </goals>                </execution>             </executions>          </plugin>       </plugins>    </build> </profile>

为了在 OpenShift 上部署它,请为其创建一个新的 OpenShift 命名空间:

oc new-project test -Popenshift

现在,从您的 Fuse 项目目录中,使用 fabric8 插件部署 Fuse 项目:

mvn fabric8:deploy

几分钟后,您的项目将可用。检查其 Pod 的可用性:

oc get pods NAME                             READY   STATUS   RESTARTS   AGE fuse74-spring-boot                 1/1      Running                0       1m

如果您检查项目的日志,您将看到 Route 已被激活,只要 Pod 已启动:

16:47:33.328 [main] INFO  o.s.b.c.e.t.TomcatEmbeddedServletContainer - Tomcat started on port(s): 8080 (http) 16:47:33.332 [main] INFO  org.mycompany.Application - Started Application in 5.807 seconds (JVM running for 6.197) 16:47:34.287 [Camel (MyCamel) thread #2 - timer://foo] INFO  simple-route - >>> Hello World from camel-context.xml 16:47:35.270 [Camel (MyCamel) thread #2 - timer://foo] INFO  simple-route - >>> Hello World from camel-context.xml 16:47:36.269 [Camel (MyCamel) thread #2 - timer://foo] INFO  simple-route - >>> Hello World from camel-context.xml 16:47:37.269 [Camel (MyCamel) thread #2 - timer://foo] INFO  simple-route - >>> Hello World from camel-context.xml

恭喜,您刚刚成功地在 OpenShift 上运行了您的第一个 Fuse 7 应用程序!

相关文章

微信公众号

最新文章

更多