3.2. Istio API を使用してゲートウェイ経由で Egress トラフィックを誘導する


Istio API を使用して、ゲートウェイインジェクションを使用してインストールされたゲートウェイを介して送信 HTTP トラフィックを誘導します。

前提条件

  • ゲートウェイインジェクションを使用してゲートウェイをインストールしている。

手順

  1. 次のコマンドを実行して、curl という名前の namespace を作成します。

    $ oc create namespace curl
  2. 使用している更新ストラテジーに応じて、適切なコマンドを実行して namespace でサイドカーインジェクションを有効にします。

    1. InPlace 更新ストラテジーを使用している場合は、次のコマンドを実行します。

      $ oc label namespace curl istio-injection=enabled
    2. RevisionBased 更新ストラテジーを使用している場合は、次のコマンドを実行します。

      1. 次のコマンドを実行してリビジョン名を表示します。

        $ oc get istiorevisions.sailoperator.io

        出力例

        NAME              TYPE    READY   STATUS    IN USE   VERSION   AGE
        default-v1-23-0   Local   True    Healthy   True     v1.23.0   3m33s

      2. 次のコマンドを実行して、namespace にリビジョン名のラベルを付け、サイドカーインジェクションを有効にします。

        $ oc label namespace curl istio.io/rev=default-v1-23-0
  3. 次のコマンドを実行して、curl アプリケーションをデプロイします。

    $ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml
  4. curl Pod の名前で初期化された CURL_POD 環境変数をエクスポートします。

    $ export CURL_POD=$(oc get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')
  5. メッシュから外部サービスにトラフィックを誘導する http-se.yaml という名前の YAML ファイルを作成します。次の例では、URL の ServiceEntry を定義します。

    設定例

    apiVersion: networking.istio.io/v1
    kind: ServiceEntry
    metadata:
      name: egress-se
      namespace: curl
    spec:
      hosts:
        - docs.redhat.com
      ports:
        - number: 80
          name: http-port
          protocol: HTTP
      location: MESH_EXTERNAL
      resolution: DNS

  6. 以下のコマンドを実行して、YAML ファイルを適用します。

    $ oc apply -f http-se.yaml
  7. ServiceEntry 設定が正しく適用されていることを確認します。次のコマンドを実行して、前の手順で指定したホストに HTTP リクエストを送信します。

    $ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com

    このコマンドは、接続が機能していることを示す 301 (リダイレクト) または 200 (成功) などの HTTP ステータスコードを返します。

  8. Egress Gateway を作成し、メッシュからのトラフィックを外部サービスに指定されたホストにルーティングする http-gtw.yaml という名前の YAML ファイルを作成します。

    設定例

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: egress-gw
      namespace: <gateway_namespace> # Namespace where the egress gateway is deployed
    spec:
      selector:
        istio: <gateway_name> # Selects the egress-gateway instance to handle this traffic
      servers:
        - port:
            number: 80
            name: http
            protocol: HTTP
          hosts:
            - docs.redhat.com # External service host, not a full URL.
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: egress-dr
      namespace: <gateway_namespace> # Namespace where the egress gateway is deployed
    spec:
      host: <gateway_name>.<gateway_namespace>.svc.cluster.local
      subsets:
        - name: rh-docs

  9. 以下のコマンドを実行して、YAML ファイルを適用します。

    $ oc apply -f http-gtw.yaml
  10. アプリケーションサイドカーから Egress ゲートウェイを経由して外部ホストまでのトラフィックのフローを管理する VirtualService をセットアップする http-vs.yaml という名前の YAML ファイルを作成します。

    設定例

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: egress-vs
      namespace: curl # Namespace where the curl pod is running
    spec:
      hosts:
        - docs.redhat.com # External service host, not a full URL.
      gateways:
        - mesh
        - <gateway_namespace>/egress-gw # Egress gateway name defined in the file that you used in the previous step.
      http:
        - match:
            - gateways:
                - mesh
              port: 80
          route:
            - destination:
                host: <gateway_name>.<gateway_namespace>.svc.cluster.local
                subset: rh-docs
                port:
                  number: 80
              weight: 100
        - match:
            - gateways:
                - <gateway_namespace>/egress-gw # Egress gateway name defined in the file that you used in the previous step.
              port: 80
          route:
            - destination:
                host: docs.redhat.com
                port:
                  number: 80
              weight: 100

  11. 以下のコマンドを実行して、YAML ファイルを適用します。

    $ oc apply -f http-vs.yaml
  12. HTTP リクエストを URL に再送信します。

    $ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com

    ターミナルには、以下の出力に似た情報が表示されます。

    出力例

    ...
    HTTP/1.1 301 Moved Permanently
    ...
    location: <example_url>
    ...
    
    HTTP/2 200
    Content-Type: text/html; charset=utf-8

  13. 次のコマンドを実行して、リクエストがゲートウェイ経由でルーティングされたことを確認します。

    $ oc logs deployment/<gateway_name> -n <gateway_namespace> | tail -1
    注記

    この検証手順を実行するには、アクセスロギングを有効にする必要があります。Istio リソースで spec.values.meshConfig.accessLogFile フィールドを /dev/stdout に設定することで、標準出力へのアクセスロギングを有効にできます。

    ターミナルには、以下の出力に似た情報が表示されます。

    出力例

    [2024-11-07T14:35:52.428Z] "GET / HTTP/2" 301 - via_upstream - "-" 0 0 24 24 "10.128.2.30" "curl/8.11.0" "79551af2-341b-456d-b414-9220b487a03b" "docs.redhat.com" "23.55.176.201:80" outbound|80||docs.redhat.com 10.128.2.29:49766 10.128.2.29:80 10.128.2.30:38296 -

Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

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

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

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

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

会社概要

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

© 2024 Red Hat, Inc.