3.4. Camel K インテグレーションの実行
kamel run コマンドを使用すると、コマンドラインから OpenShift クラスターのクラウドで Camel K インテグレーションを実行できます。
前提条件
- Camel K 開発環境の設定
- Java または YAML DSL で記述された Camel インテグレーションが作成済みである。
手順
以下の例のように、
ocクライアントツールを使用して OpenShift クラスターにログインします。$ oc login --token=my-token --server=https://my-cluster.example.com:6443以下の例のように、Camel K Operator が稼働していることを確認します。
$ oc get pod NAME READY STATUS RESTARTS AGE camel-k-operator-86b8d94b4-pk7d6 1/1 Running 0 6m28skamel runコマンドを入力し、OpenShift のクラウドでインテグレーションを実行します。以下に例を示します。Java の例
$ kamel run HelloCamelK.java integration "hello-camel-k" createdYAML の例
$ kamel run hello.camelk.yaml integration "hello" createdkamel getコマンドを入力し、インテグレーションの状態を確認します。$ kamel get NAME PHASE KIT hello Building Kit myproject/kit-bq666mjej725sk8sn12gインテグレーションが初めて実行されると、Camel K はコンテナーイメージのインテグレーションキットをビルドします。インテグレーションキットは、必要なすべての Camel モジュールをダウンロードし、イメージクラスパスに追加します。
kamel getを再度入力して、インテグレーションが稼働していることを確認します。$ kamel get NAME PHASE KIT hello Running myproject/kit-bq666mjej725sk8sn12gkamel 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] ...-
Ctrl-Cキーを押して、ターミナルでログインを終了します。
関連情報
-
kamel runコマンドの詳細については、kamel run --helpを入力してください。 - デプロイメントのターンアラウンド時間を短縮するには、開発モードでの Camel K インテグレーションの実行 を参照してください。
- インテグレーションを実行するための開発ツールの詳細は、Red Hat による Apache Camel K の VS Code ツール を参照してください。
- Camel K インテグレーションの管理 も参照してください。
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 が統合を実行します。
- Kubernetes は、CustomResourceDefinitions の 構造スキーマ をサポートしています。
- Camel K トレイトの詳細については、Camel K トレイト設定リファレンス を参照してください。
カスタムリソースのスキーマの変更
厳密に型指定された Trait API は、CustomResourceDefinitions である integrations、'integrationkits', and 'integrationplatforms' を変更します。
spec.traits.<trait-id>.configuration の下のトレイトプロパティーは、spec.traits.<trait-id> の下で直接定義されるようになりました。
traits:
container:
configuration:
enabled: true
name: my-integration
↓↓↓
traits:
container:
enabled: true
name: my-integration
この実装では、下位互換性が可能です。下位互換性を実現するために、RawMessage タイプの Configuration フィールドが各トレイトタイプに提供され、既存の統合とリソースが新しい 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"`
}