3.3. Kubernetes Gateway API を使用してゲートウェイ経由で Egress トラフィックを送信する


Kubernetes Gateway API を使用して、送信 HTTP トラフィックを Egress ゲートウェイ経由で送信します。

前提条件

  • Istio コントロールプレーンをインストールした。
  • Istio および IstioCNI リソースを設定した。

手順

  1. オプション: {k8} Gateway API カスタムリソース定義 (CRD) を有効にします。

    注記

    Kubernetes 1.28 および OpenShift Container Platform 4.18 以前のバージョンの Red Hat OpenShift Service Mesh では、Kubernetes Gateway API CRD はデフォルトでは使用できないため、使用する前に CRD を有効にする必要があります。OpenShift Container Platform 4.19 以降のバージョンでは、CRD がデフォルトで有効になっています。

    1. Kubernetes Gateway API CRD を有効にする、gateway-cr.yaml という名前の YAML ファイルを作成します。

      Kubernetes Gateway カスタムリソース (CR) ファイルの例

      apiVersion: gateway.networking.k8s.io/v1
      kind: Gateway
      metadata:
        name: info-gateway
      spec:
        gatewayClassName: istio
        listeners:
        - name: http
          port: 80
          protocol: HTTP
          allowedRoutes:
            namespaces:
              from: Same
      ---
      apiVersion: gateway.networking.k8s.io/v1
      kind: HTTPRoute
      metadata:
        name: info
      spec:
        parentRefs:
        - name: info-gateway
        rules:
        - matches:
          - path:
              type: Exact
              value: /productpage
          - path:
              type: PathPrefix
              value: /static
          - path:
              type: Exact
              value: /login
          - path:
              type: Exact
              value: /logout
          - path:
              type: PathPrefix
              value: /api/v1/products
          backendRefs:
          - name: productpage
            port: 9080
      Copy to Clipboard Toggle word wrap

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

      $ oc apply -f gateway-cr.yaml
      Copy to Clipboard Toggle word wrap
  2. 次のコマンドを実行して、Egress-gateway という namespace を作成します。

    $ oc create namespace egress-gateway
    Copy to Clipboard Toggle word wrap
  3. 次のコマンドを実行して、その namespace に istio-injection ラベルを適用します。

    $ oc label namespace egress-gateway istio-injection=enabled
    Copy to Clipboard Toggle word wrap
  4. Egress ゲートウェイを定義する、egress -gateway-cr.yaml という名前の YAML ファイルを作成します。

    Egress ゲートウェイ CR ファイルの例

    # ServiceEntry to allow traffic to httpbin.org
    apiVersion: networking.istio.io/v1
    kind: ServiceEntry
    metadata:
      name: httpbin-ext
    spec:
      hosts:
      - httpbin.org
      ports:
      - number: 80
        name: http
        protocol: HTTP
      location: MESH_EXTERNAL
      resolution: DNS
    ---
    # Gateway API Gateway for egress
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: httpbin-egress-gateway
      annotations:
        networking.istio.io/service-type: ClusterIP
    spec:
      gatewayClassName: istio
      listeners:
      - name: http
        hostname: httpbin.org
        port: 80
        protocol: HTTP
        allowedRoutes:
          namespaces:
            from: Same
    ---
    # HTTPRoute to direct traffic from sidecars to the egress gateway
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: direct-httpbin-to-egress-gateway
    spec:
      parentRefs:
      - kind: ServiceEntry
        group: networking.istio.io
        name: httpbin-ext
      rules:
      - backendRefs:
        - name: httpbin-egress-gateway-istio
          port: 80
    ---
    # HTTPRoute to forward traffic from the egress gateway to httpbin.org
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: forward-httpbin-from-egress-gateway
    spec:
      parentRefs:
      - name: httpbin-egress-gateway
      hostnames:
      - httpbin.org
      rules:
      - backendRefs:
        - kind: Hostname
          group: networking.istio.io
          name: httpbin.org
          port: 80
    Copy to Clipboard Toggle word wrap

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

      $ oc apply -f egress-gateway-cr.yaml
      Copy to Clipboard Toggle word wrap

検証

  1. 次のコマンドを実行して、ゲートウェイ設定のステータスを確認します。

    $ oc describe gateway -n egress-gateway
    Copy to Clipboard Toggle word wrap

    目的の出力の Status 列には、Programmed が表示されます。

  2. 次のコマンドを実行して、Egress-gateway namespace に curl Pod を作成します。

    $ oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- sh
    Copy to Clipboard Toggle word wrap
  3. curl クライアントを使用し、次のコマンドを入力して Egress ゲートウェイ経由で httpbin.org にアクセスできることを確認します。

    $ curl -v http://httpbin.org/get
    Copy to Clipboard Toggle word wrap

    目的の出力には、設定されたゲートウェイを通過する Egress トラフィックのルートを示す httpbin.org からのレスポンスが表示されます。

トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

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

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

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

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

会社概要

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

Theme

© 2025 Red Hat