HTTPリクエストが失敗した場合に使用される再試行ポリシー (各再試行のタイムアウト、再試行回数、再試行条件など) を定義できます。このトピックでは、再試行ポリシーを構成する方法について説明します。
前提条件
準備が完了し、HTTPBinサービスとsleepサービスがデプロイされています。詳細については、準備をご参照ください。
手順
サービス構成が有効になっているかどうかを確認します。
ACK クラスターの kubeconfig 環境で、次のコマンドを実行して 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
次の内容を使用して、仮想サービスを作成します。この仮想サービスは、
5xx応答が受信された場合に、httpbin アプリケーションへのリクエストを最大 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再試行処理のログを表示するために、ウェイポイントプロキシのログレベルを変更します。
kubectl exec -it deployment/waypoint -- curl -XPOST "http://localhost:15000/logging?level=debug"次のコマンドを実行して、ウェイポイントプロキシのログを表示します。
kubectl logs deployment/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元のログレベルに戻します。
kubectl exec -it deployment/waypoint -- curl -XPOST "http://localhost:15000/logging?level=warning"