HTTPリクエストが失敗した場合に使用される再試行ポリシー (各再試行のタイムアウト、再試行回数、再試行条件など) を定義できます。このトピックでは、再試行ポリシーを構成する方法について説明します。
前提条件
準備が完了し、HTTPBinサービスとsleepサービスがデプロイされています。詳細については、準備をご参照ください。
手順
サービス構成が有効になっているかどうかを確認します。
kubeconfigファイルの情報に基づいて、kubectlを使用してコンテナサービス 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: gunicorn/19.9.0 Date: Tue, 29 Aug 2023 02:36:24 GMT Connection: keep-alive Content-Type: text/html; charset=utf-8 Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Content-Length: 0
istioctlツールを使用して、次のコマンドを実行し、HTTPBinサービスのレイヤー 7 ウェイポイントプロキシをデプロイします。
istioctl x waypoint apply --service-account httpbin
次のコンテンツを使用して、テスト用の仮想サービスを作成し、HTTPBinサービスのトラフィックルールを構成します。再試行ポリシーは、レスポンスが
5xx
の場合、リクエストを 5 回再試行することです。詳細については、仮想サービスの管理をご参照ください。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
構成が有効になっているかどうかを確認します。
kubeconfigファイルの情報に基づいて、kubectlを使用してACKクラスタに接続し、次のコマンドを実行してsleepサービスのbashを有効にします。
kubectl exec -it deploy/sleep -- sh
次のコマンドを実行して、HTTPBinサービスにリクエストを送信します。
curl -I httpbin:8000/status/500
期待される出力:
HTTP/1.1 500 Internal Server Error server: istio-envoy date: Fri, 11 Aug 2023 07:00:19 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: 329
再試行処理のログを表示するために、ウェイポイントプロキシのログレベルを変更します。
次のコマンドを実行して、httpbin-istio-waypoint ポッドにアクセスします。
kubectl exec -it {httpbin-istio-waypoint ポッドの名前} -- sh
次のコマンドを実行して、ウェイポイントプロキシのログレベルを変更します。
curl -XPOST http://localhost:15000/logging\?level\=debug
次のコマンドを実行して、ウェイポイントプロキシのログを表示します。
kubectl logs {httpbin-istio-waypoint ポッドの名前} | grep -i retry
期待される出力:
2023-08-11T07:00:19.512883Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.516388Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.547553Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.633248Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25 2023-08-11T07:00:19.829611Z debug envoy router external/envoy/source/common/router/router.cc:1862 [C1080][S1651638534493129****] performing retry thread=25