This guide demonstrates how to configure retry policy for a client and server application within the service mesh.
Prerequisites
- Kubernetes cluster running Kubernetes v1.22.9 or greater.
- Have
kubectlavailable to interact with the API server. - Have
osmCLI available for managing the service mesh.
Demo
-
Install OSM with permissive mode and retry policy enabled.
osm install --set=osm.enablePermissiveTrafficPolicy=true --set=osm.featureFlags.enableRetryPolicy=true -
Deploy the
httpbinservice into thehttpbinnamespace after enrolling its namespace to the mesh. Thehttpbinservice runs on port14001.kubectl create namespace httpbin osm namespace add httpbin kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.2/manifests/samples/httpbin/httpbin.yaml -n httpbinConfirm the
httpbinservice and pods are up and running.kubectl get svc,pod -n httpbinShould look similar to below
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE httpbin ClusterIP 10.96.198.23 <none> 14001/TCP 20s NAME READY STATUS RESTARTS AGE httpbin-5b8b94b9-lt2vs 2/2 Running 0 20s -
Deploy the
curlinto thecurlnamespace after enrolling its namespace to the mesh.kubectl create namespace curl osm namespace add curl kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/release-v1.2/manifests/samples/curl/curl.yaml -n curlConfirm the
curlpod is up and running.kubectl get pods -n curlShould look similar to below
NAME READY STATUS RESTARTS AGE curl-54ccc6954c-9rlvp 2/2 Running 0 20s -
Apply the Retry policy to retry when the
curlServiceAccount receives a5xxcode when sending a request tohttpbinService.kubectl apply -f - <<EOF kind: Retry apiVersion: policy.openservicemesh.io/v1alpha1 metadata: name: retry namespace: curl spec: source: kind: ServiceAccount name: curl namespace: curl destinations: - kind: Service name: httpbin namespace: httpbin retryPolicy: retryOn: "5xx" perTryTimeout: 1s numRetries: 5 retryBackoffBaseInterval: 1s EOF -
Send a HTTP request that returns status code
503from thecurlpod to thehttpbinservice.kubectl exec deploy/curl -n curl -c curl -- curl -sI httpbin.httpbin.svc.cluster.local:14001/status/503 -
In a new terminal session, run the following command to port-forward the
curlpod.kubectl port-forward deploy/curl -n curl 15000 -
Query for the stats between
curltohttpbin.curl -s localhost:15000/stats | grep "cluster.httpbin/httpbin|14001.upstream_rq_retry"The number of times the request from the
curlpod to thehttpbinpod was retried using the exponential backoff retry should be equal to thenumRetriesfield in the retry policy. Theupstream_rq_retry_limit_exceededstat shows the number of requests not retried because it’s more than the maximum retries allowed -numRetries.cluster.httpbin/httpbin|14001.upstream_rq_retry: 5 cluster.httpbin/httpbin|14001.upstream_rq_retry_backoff_exponential: 5 cluster.httpbin/httpbin|14001.upstream_rq_retry_backoff_ratelimited: 0 cluster.httpbin/httpbin|14001.upstream_rq_retry_limit_exceeded: 1 cluster.httpbin/httpbin|14001.upstream_rq_retry_overflow: 0 cluster.httpbin/httpbin|14001.upstream_rq_retry_success: 0 -
Send a HTTP request that returns a non-5xx status code from the
curlpod to thehttpbinservice.kubectl exec deploy/curl -n curl -c curl -- curl -sI httpbin.httpbin.svc.cluster.local:14001/status/404 -
The
envoy_cluster_upstream_rq_retrymetric does not increment since the retry policy is set to retry on5xx
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.