3.4. 运行 Camel K 集成


您可以使用 kamel run 命令从命令行运行 OpenShift 集群上的 Camel K 集成。

先决条件

流程

  1. 使用 oc 客户端工具登录到 OpenShift 集群,例如:

    $ oc login --token=my-token --server=https://my-cluster.example.com:6443
  2. 确保 Camel K Operator 正在运行,例如:

    $ oc get pod
    NAME                               READY   STATUS    RESTARTS   AGE
    camel-k-operator-86b8d94b4-pk7d6   1/1     Running   0          6m28s
  3. 输入 kamel run 命令,以在 OpenShift 上的云中运行集成。例如:

    Java 示例

    $ kamel run HelloCamelK.java
    integration "hello-camel-k" created

    YAML 示例

    $ kamel run hello.camelk.yaml
    integration "hello" created

  4. 输入 kamel get 命令来检查集成的状态:

    $ kamel get
    NAME       PHASE           KIT
    hello      Building Kit    myproject/kit-bq666mjej725sk8sn12g

    当集成首次运行时,Camel K 为容器镜像构建集成工具包,它会下载所有必要的 Camel 模块,并将它们添加到镜像类路径中。

  5. 再次输入 kamel get 来验证集成是否正在运行:

    $ kamel get
    NAME       PHASE   KIT
    hello      Running myproject/kit-bq666mjej725sk8sn12g
  6. 输入 kamel log 命令将日志输出到 stdout

    $ kamel log hello
    [1] 2021-08-11 17:58:40,573 INFO  [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 1.7.1.fuse-800025-redhat-00001
    [1] 2021-08-11 17:58:40,653 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
    [1] 2021-08-11 17:58:40,844 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='camel-k-embedded-flow', language='yaml', location='file:/etc/camel/sources/camel-k-embedded-flow.yaml', }
    [1] 2021-08-11 17:58:41,216 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup summary (total:1 started:1)
    [1] 2021-08-11 17:58:41,217 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started route1 (timer://yaml)
    [1] 2021-08-11 17:58:41,217 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.10.0.fuse-800010-redhat-00001 (camel-1) started in 136ms (build:0ms init:100ms start:36ms)
    [1] 2021-08-11 17:58:41,268 INFO  [io.quarkus] (main) camel-k-integration 1.6.6 on JVM (powered by Quarkus 1.11.7.Final-redhat-00009) started in 2.064s.
    [1] 2021-08-11 17:58:41,269 INFO  [io.quarkus] (main) Profile prod activated.
    [1] 2021-08-11 17:58:41,269 INFO  [io.quarkus] (main) Installed features: [camel-bean, camel-core, camel-k-core, camel-k-runtime, camel-log, camel-support-common, camel-timer, camel-yaml-dsl, cdi]
    [1] 2021-08-11 17:58:42,423 INFO  [info] (Camel (camel-1) thread #0 - timer://yaml) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K from yaml]
    ...
  7. Ctrl-C 终止终端中的日志记录。

其他资源

在 CLI 中运行集成

您可以在没有 CLI (命令行接口)的情况下运行集成,并使用配置创建一个 集成自定义资源 以运行应用程序。

例如,执行以下示例路由。

kamel run Sample.java -o yaml

它返回预期的集成自定义资源。

apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  creationTimestamp: null
  name: my-integration
  namespace: default
spec:
  sources:
  - content: "
    import org.apache.camel.builder.RouteBuilder;
    public class Sample extends RouteBuilder {
      @Override
      public void configure()
      throws Exception {
        from(\"timer:tick\")
        .log(\"Hello Integration!\");
       }
      }"
    name: Sample.java
status: {}

将此自定义资源保存到 yaml 文件 my-integration.yaml 中。现在,使用 oc 命令行、UI 或 API 调用 OpenShift 集群,运行包含集成自定义资源的集成。在以下示例中,从命令行使用 oc CLI。

oc apply -f my-integration.yaml
...
integration.camel.apache.org/my-integration created

Operator 运行 Integration。

注意

自定义资源的模式更改

强烈输入的 Trait API 对以下 CustomResourceDefinitions 进行了更改: 集成integrationkits' 和 'integrationplatforms。

spec.traits.<traits.<traits.<traits.< traits .<traits.<traits.<traits> 下的特征属性现在直接定义。

traits:
  container:
    configuration:
      enabled: true
      name: my-integration

↓↓↓

traits:
  container:
    enabled: true
    name: my-integration

在这个实现中可以向后兼容。为了实现向后兼容,会为每个特征类型提供带有 RawMessage 类型的 Configuration 字段,以便现有集成和资源从新的红帽构建的 Apache Camel K 版本中读取。

当读取旧的集成和资源时,每个特征中的旧配置(若有)将迁移到新的 Trait API 字段。如果在新的 API 字段中预定义了值,它们会先于旧的字段。

type Trait struct {
    // Can be used to enable or disable a trait. All traits share this common property.
    Enabled *bool `property:"enabled" json:"enabled,omitempty"`

    // Legacy trait configuration parameters.
    // Deprecated: for backward compatibility.
    Configuration *Configuration `json:"configuration,omitempty"`
}

// Deprecated: for backward compatibility.
type Configuration struct {
    RawMessage `json:",inline"`
}
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.