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.3.2. Istio API を使用してゲートウェイ経由で Egress トラフィックを誘導する
Istio API を使用して、ゲートウェイインジェクションを使用してインストールされたゲートウェイを介して送信 HTTP トラフィックを誘導します。
前提条件
- ゲートウェイインジェクションを使用してゲートウェイをインストールしている。
手順
次のコマンドを実行して、
curl
という名前の namespace を作成します。$ oc create namespace curl
使用している更新ストラテジーに応じて、適切なコマンドを実行して namespace でサイドカーインジェクションを有効にします。
InPlace
更新ストラテジーを使用している場合は、次のコマンドを実行します。$ oc label namespace curl istio-injection=enabled
RevisionBased
更新ストラテジーを使用している場合は、次のコマンドを実行します。次のコマンドを実行してリビジョン名を表示します。
$ 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 curl istio.io/rev=default-v1-23-0
次のコマンドを実行して、
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
環境変数をエクスポートします。$ export CURL_POD=$(oc get pod -n curl -l app=curl -o jsonpath='{.items[0].metadata.name}')
メッシュから外部サービスにトラフィックを誘導する
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
以下のコマンドを実行して、YAML ファイルを適用します。
$ oc apply -f http-se.yaml
ServiceEntry
設定が正しく適用されていることを確認します。次のコマンドを実行して、前の手順で指定したホストに HTTP リクエストを送信します。$ oc exec "$CURL_POD" -n curl -c curl -- curl -sSL -o /dev/null -D - http://docs.redhat.com
このコマンドは、接続が機能していることを示す
301
(リダイレクト) または200
(成功) などの HTTP ステータスコードを返します。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
以下のコマンドを実行して、YAML ファイルを適用します。
$ oc apply -f http-gtw.yaml
アプリケーションサイドカーから 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
以下のコマンドを実行して、YAML ファイルを適用します。
$ oc apply -f http-vs.yaml
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
次のコマンドを実行して、リクエストがゲートウェイ経由でルーティングされたことを確認します。
$ 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 -