OpenShift Service Mesh 3.0 is a Technology Preview feature only
Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. This documentation is a work in progress and might not be complete or fully tested.第2章 トラフィックをメッシュに取り込む
Istio API を使用すると、ゲートウェイインジェクションを使用してインストールされたゲートウェイプロキシーを設定して、メッシュ外部からのトラフィックを受け入れ、そのトラフィックをメッシュ内のサービスにルーティングできます。
LoadBalancer
タイプの Service
または OpenShift Routes
のいずれかを使用して、ゲートウェイプロキシーをクラスター外部のトラフィックに公開できます。
2.1. ゲートウェイインジェクションを使用してインストールされたゲートウェイを Ingress トラフィックを受け入れるように設定することについて
ゲートウェイインジェクションを使用してゲートウェイをインストールすると、Istio Gateway
と VirtualService
リソースを組み合わせて Ingress トラフィックを受信するようにゲートウェイを設定できます。Istio Gateway
リソースは、着信または発信の HTTP/TCP 接続を受信するメッシュのエッジで動作するロードバランサーを表します。Gateway
仕様には、公開する必要があるポートのセット、使用するプロトコルのタイプ、およびロードバランサーの Server Name Indication (SNI) 設定が記述されています。VirtualServices
は、VirtualServices
を使用して内部メッシュトラフィックのルーティングルールを定義するのと同様に、Istio Gateway
に適用するルーティングルールを定義します。
次の例では、Istio Gateway
リソースは、外部トラフィックのエントリーポイントとして機能するゲートウェイプロキシーを設定します。この設定では、ホスト info.com
のポート 443 (HTTPS) が公開されます。この設定例は、istio: ingressgateway
ラベルを持つ Pod に適用されます。tls
モードは SIMPLE
と設定され、例で提供される証明書と秘密鍵を使用して着信 HTTPS トラフィックを終了します。
設定サンプル
apiVersion: networking.istio.io/v1 kind: Gateway metadata: name: info-gateway namespace: info spec: selector: istio: ingressgateway servers: - port: number: 443 name: https-443 protocol: HTTPS hosts: - info.com tls: mode: SIMPLE serverCertificate: /etc/certs/servercert.pem privateKey: /etc/certs/privatekey.pem
次の VirtualService
は、前の設定例に示されている Istio Gateway
リソースにバインドされています。この仕様では、/reviews/
パス接頭辞を持つトラフィックを info
namespace のレビューサービスにルーティングするためのルールが定義されています。VirtualService
は、前に示した Gateway
リソースを明示的に参照します。これにより、指定されたゲートウェイを通じて入ってくるトラフィックにのみルーティングルールが適用されるようになります。
設定サンプル
kind: VirtualService metadata: name: info-rule namespace: info spec: hosts: - info.com gateways: - info/bookinfo-gateway http: - match: - uri: prefix: /reviews/ route: - destination: port: number: 9080 host: reviews.info.svc.cluster.local
関連情報
2.1.1. Istio Gateway と VirtualService リソースを使用してサービスを公開する
この手順では、Istio Gateway
および VirtualService
リソースを使用して、ゲートウェイインジェクションを使用してデプロイされたゲートウェイを設定します。リソースは、メッシュ内のサービスをメッシュ外のトラフィックに公開するようにゲートウェイを設定します。次に、ゲートウェイの Service
を LoadBalancer
タイプに設定して、ゲートウェイをクラスター外部のトラフィックに公開します。
前提条件
- ゲートウェイインジェクションを使用して Istio ゲートウェイをインストールしている。
手順
次のコマンドを実行して、
httpbin
という namespace を作成します。$ oc create namespace httpbin
namespace でサイドカーインジェクションを有効にします。
InPlace
アップグレードストラテジーを使用している場合は、次のコマンドを実行します。$ oc label namespace httpbin istio-injection=enabled
注記RevisionBased
アップグレードストラテジーを使用している場合は、次のコマンドを実行します。<revision-name>
を見つけるには、次のコマンドを実行します。$ 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
サイドカーインジェクションを有効にするには、namespace にリビジョン名でラベルを付けます。
$ oc label namespace httpbin istio.io/rev=default-v1-23-0
次のコマンドを実行して、
httpbin
という名前のサンプルサービスをデプロイします。$ oc apply -n httpbin -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yaml
Istio
Gateway
リソースを定義するhttpbin-gw.yaml
という名前の YAML ファイルを作成します。このリソースは、ホストhttpbin.example.com
のポート 80 (HTTP) を公開するようにゲートウェイプロキシーを設定します。apiVersion: networking.istio.io/v1 kind: Gateway metadata: name: httpbin-gateway namespace: httpbin spec: selector: istio: <gateway_name> 1 servers: - port: number: 80 name: http protocol: HTTP hosts: - httpbin.example.com 2
以下のコマンドを実行して、YAML ファイルを適用します。
$ oc apply -f httpbin-gw.yaml
VirtualService
用にhttpbin-vs.yaml
という名前の YAML ファイルを作成します。VirtualService
は、ゲートウェイプロキシーからhttpbin
サービスにトラフィックをルーティングするルールを定義します。apiVersion: networking.istio.io/v1 kind: VirtualService metadata: name: httpbin namespace: httpbin spec: hosts: - httpbin.example.com 1 gateways: - httpbin-gateway 2 http: - match: - uri: prefix: /status - uri: prefix: /headers route: - destination: 3 port: number: 8000 host: httpbin
- 1
VirtualService
のルーティングルールが適用されるhosts
を指定します。指定されたhosts
は、VirtualService がバインドされている IstioGateway
リソースによって公開される必要があります。- 2
Gateway
名をゲートウェイのリストに追加して、前の手順で作成した IstioGateway
リソースにVirtualService
をバインドします。- 3
httpbin
Service
のhost
とport
を含むdestination
を定義して、一致するトラフィックを以前デプロイしたhttpbin
サービスにルーティングします。
以下のコマンドを実行して、YAML ファイルを適用します。
$ oc apply -f httpbin-vs.yaml
検証のために、次のコマンドを実行して
curl
クライアントの namespace を作成します。$ oc create namespace curl
次のコマンドを実行して
curl
クライアントをデプロイします。$ oc apply -n curl -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/curl/curl.yaml
次のコマンドを実行して、
curl
Pod の名前でCURL_POD
変数を設定します。$ CURL_POD=$(oc get pods -n curl -l app=curl -o jsonpath='{.items[*].metadata.name}')
curl
クライアントを使用して、Ingress ゲートウェイService
リソースを介してhttpbin
アプリケーションの/headers
エンドポイントにリクエストを送信します。IstioGateway
およびVirtualService
リソースが指定するホストと一致するように、リクエストのHost
ヘッダーをhttpbin.example.com
に設定します。リクエストを送信するには、次のcurl
コマンドを実行します。$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>.<gateway_namespace>.svc.cluster.local/headers
応答には、リクエストが成功したことを示す
200 OK HTTP
ステータスが含まれます。出力例
HTTP/1.1 200 OK server: istio-envoy ...
次のコマンドを実行して、
httpbin
VirtualService
に対応する URI プレフィックスの一致が定義されていないエンドポイントに curl リクエストを送信します。$ oc exec $CURL_POD -n curl -- \ curl -s -I \ -H Host:httpbin.example.com \ <gateway_name>.<gateway_namespace>.svc.cluster.local/get
応答では
404 Not Found
ステータスが返されます。/get
エンドポイントには、httpbin
VirtualService
リソース内に一致する URI 接頭辞がないため、これは予想された結果です。出力例
HTTP/1.1 404 Not Found server: istio-envoy ...
Service
タイプをLoadBalancer
に設定して、ゲートウェイプロキシーをクラスター外部のトラフィックに公開します。$ oc patch service <gateway_name> -n <gateway_namespace> -p '{"spec": {"type": "LoadBalancer"}}'
注記OpenShift Routes を使用して、ゲートウェイをクラスター外部のトラフィックに公開することもできます。詳細は、「OpenShift Routes を使用してゲートウェイをクラスター外のトラフィックに公開する」を参照してください。
ゲートウェイ
Service
リソースの外部ホスト名または IP アドレスを使用する場合は、クラスターの外部からhttpbin
サービスにアクセスできることを確認します。クラスターが実行されている環境に合わせて、INGRESS_HOST
変数を適切に設定してください。クラスターが AWS 上で実行されている場合は、次のコマンドを実行して
INGRESS_HOST
変数を設定します。$ INGRESS_HOST=$(oc get service <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
クラスターが GCP または Azure 上で実行されている場合は、次のコマンドを実行して
INGRESS_HOST
変数を設定します。$ INGRESS_HOST=$(oc get service <gateway_name> -n <gateway_namespace> -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
次のコマンドを実行し、ゲートウェイのホストを使用して
httpbin
サービスにcurl
リクエストを送信します。$ curl -s -I -H Host:httpbin.example.com http://$INGRESS_HOST/headers
-
応答に
HTTP/1.1 200 OK
ステータスがあることを確認します。これは、リクエストが成功したことを示します。