検索

第12章 Service Mesh での ContainerSource の使用

download PDF

Service Mesh でコンテナーソースを使用できます。

12.1. Service Mesh を使用した ContainerSource の設定

この手順では、Service Mesh を使用してコンテナーソースを設定する方法を説明します。

前提条件

  • Service Mesh と Serverless の統合が設定されている。

手順

  1. ServiceMeshMemberRoll のメンバーである namespace に Service を作成します。

    event-display-service.yaml 設定ファイルの例

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: event-display
      namespace: <namespace> 1
    spec:
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "true" 2
            sidecar.istio.io/rewriteAppHTTPProbers: "true"
        spec:
          containers:
          - image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest

    1
    ServiceMeshMemberRoll のメンバーである namespace。
    2
    このアノテーションは、Service Mesh サイドカーを Knative サービス Pod に挿入します。
  2. Service リソースを適用します。

    $ oc apply -f event-display-service.yaml
  3. ServiceMeshMemberRoll のメンバーである namespace に ContainerSource を作成し、event-display に設定されたシンクを作成します。

    test-heartbeats-containersource.yaml 設定ファイルの例

    apiVersion: sources.knative.dev/v1
    kind: ContainerSource
    metadata:
      name: test-heartbeats
      namespace: <namespace> 1
    spec:
      template:
        metadata: 2
          annotations:
            sidecar.istio.io/inject": "true"
            sidecar.istio.io/rewriteAppHTTPProbers: "true"
        spec:
          containers:
            # This corresponds to a heartbeats image URI that you have built and published
            - image: quay.io/openshift-knative/heartbeats
              name: heartbeats
              args:
                - --period=1s
              env:
                - name: POD_NAME
                  value: "example-pod"
                - name: POD_NAMESPACE
                  value: "event-test"
      sink:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: event-display-service

    1
    ServiceMeshMemberRoll の一部である namespace。
    2
    これらのアノテーションにより、Service Mesh と ContainerSource オブジェクトの統合が可能になります。
  4. ContainerSource リソースを適用します。

    $ oc apply -f test-heartbeats-containersource.yaml
  5. オプション: メッセージダンパー機能のログを調べて、イベントが Knative イベントシンクに送信されたことを確認します。

    コマンドの例

    $ oc logs $(oc get pod -o name | grep event-display) -c user-container

    出力例

    ☁️  cloudevents.Event
    Validation: valid
    Context Attributes,
      specversion: 1.0
      type: dev.knative.eventing.samples.heartbeat
      source: https://knative.dev/eventing-contrib/cmd/heartbeats/#event-test/mypod
      id: 2b72d7bf-c38f-4a98-a433-608fbcdd2596
      time: 2019-10-18T15:23:20.809775386Z
      contenttype: application/json
    Extensions,
      beats: true
      heart: yes
      the: 42
    Data,
      {
        "id": 1,
        "label": ""
      }

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.