Service Mesh(ASM)では、HTTPリクエストが失敗した場合に使用される再試行ポリシー(各再試行のタイムアウト、再試行回数、再試行条件など)を定義できます。このトピックでは、再試行ポリシーを構成する方法について説明します。
前提条件
準備が完了し、HTTPBinサービスとsleepサービスがデプロイされています。詳細については、「準備」をご参照ください。
手順
サービス構成が有効になっているかどうかを確認します。
kubeconfigファイルの情報に基づいて、kubectlを使用してContainer Service for Kubernetes(ACK)クラスターに接続し、次のコマンドを実行してsleepサービスのbashを有効にします。
kubectl exec -it deploy/sleep -- sh
次のコマンドを実行して、HTTPBinサービスにリクエストを送信します。
curl -I httpbin:8000/status/500
期待される出力:
HTTP/1.1 500 Internal Server Error server: envoy date: Fri, 11 Aug 2023 10:03:06 GMT content-type: text/html; charset=utf-8 access-control-allow-origin: * access-control-allow-credentials: true content-length: 0 x-envoy-upstream-service-time: 2
次のコンテンツを使用して、テスト用の仮想サービスを作成し、HTTPBinサービスのトラフィックルールを構成します。再試行ポリシーは、レスポンスが
5xx
の場合、リクエストを5回再試行することです。詳細については、「仮想サービスの管理」をご参照ください。構成が有効になっているかどうかを確認します。
kubeconfigファイルの情報に基づいて、kubectlを使用してACKクラスターに接続し、次のコマンドを実行してsleepサービスのbashを有効にします。
kubectl exec -it deploy/sleep -- sh
次のコマンドを実行して、HTTPBinサービスにリクエストを送信し、レスポンスステータスコードを 500 に設定します。
curl -I httpbin:8000/status/500
期待される出力:
HTTP/1.1 500 Internal Server Error server: envoy date: Fri, 11 Aug 2023 10:03:35 GMT content-type: text/html; charset=utf-8 access-control-allow-origin: * access-control-allow-credentials: true content-length: 0 x-envoy-upstream-service-time: 382
再試行処理のログを表示するために、sleepサービスのログレベルを変更します。
次のコマンドを実行して、sleepポッドにアクセスします。
kubectl exec -it {sleep ポッドの名前} -- sh
次のコマンドを実行して、ログレベルを変更します。
curl -XPOST http://localhost:15000/logging\?level\=debug
次のコマンドを実行して、sleepサービスのログを表示します。
kubectl logs {sleep ポッドの名前} -c istio-proxy | grep -i retry
期待される出力:
2023-08-14T02:11:01.896684Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:01.932148Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:02.020689Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:02.170440Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36 2023-08-14T02:11:02.275478Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C159776][S1686768772862290****] performing retry thread=36
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: httpbin-vs
namespace: default
spec:
hosts:
- httpbin
http:
- retries:
attempts: 5
retryOn: 5xx
route:
- destination:
host: httpbin