In this demo we’ll configure per-route request timeouts and retries in an Istio VirtualService. We’ll deploy the httpbin sample application, create a test pod withDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
curl, and demonstrate timeout and retry behavior using httpbin’s diagnostic endpoints.
- Target audience: anyone learning Istio traffic management (VirtualService).
- Tools used:
kubectl,curl, and Istio sidecar logs.
- Istio VirtualService: https://istio.io/latest/docs/reference/config/networking/virtual-service/
- httpbin: https://httpbin.org
1. Verify namespace and sidecar injection
Confirm your namespaces and labels (to check sidecar injection status if your cluster uses automatic injection):default namespace.
2. Deploy httpbin and create a test pod (with curl)
Deploy the httpbin sample application:curl and stays running so you can exec into it:
3. Verify the httpbin service and basic request
List services:/get endpoint to verify basic connectivity:
4. Implement a per-route timeout (VirtualService)
Create a VirtualService that sets a 2-second timeout for HTTP requests to thehttpbin service.
Save this as vs-timeout.yaml:
Test the timeout with httpbin’s /delay endpoint
httpbin exposes/delay/{n} which delays the response by n seconds. Use it to test the configured timeout.
- This request should succeed (delay less than timeout):
- This request should fail (delay equal to or greater than timeout):
timeout (2s), Istio will terminate the request and return an error instead of waiting for the delayed response.
Timeouts are configured per HTTP route in the VirtualService. Choose a timeout that fits expected backend latencies and the client experience you want to provide.
5. Implement retries
You can either modify the existing VirtualService or create a new one to enable retries. The example below configures up to 3 retry attempts for5xx errors, with a 2s perTryTimeout.
Save this as vs-retries.yaml:
Test retries using httpbin’s /status endpoint
httpbin exposes/status/{code} which returns the requested HTTP status code. Trigger a 500 to cause retries:
retries configuration (in this example: attempts: 3). Retry attempts are visible in the sidecar proxy logs.
Inspect istio-proxy logs to observe retries
Get the httpbin pod name:httpbin-pod with the actual pod name):
kubectl logs <httpbin-pod> -c istio-proxy and replace <httpbin-pod> with the pod name.)
In the logs you will observe the initial failing request and subsequent retry attempts issued by the proxy.
Retries are specified per HTTP route using
retries.attempts, retries.perTryTimeout, and retries.retryOn. Be cautious: retries can increase load on already failing backends.6. Key VirtualService timeout & retry fields
| Field | Purpose | Example |
|---|---|---|
timeout | Maximum lifetime for an individual request on a route | 2s |
retries.attempts | Number of retry attempts for a route | 3 |
retries.perTryTimeout | Timeout for each retry attempt | 2s |
retries.retryOn | Conditions that trigger retries (e.g., 5xx, gateway-error) | "5xx" |
7. Summary
- Configure
timeoutandretriesin an Istio VirtualService to control how requests are timed out and retried. - Use httpbin’s
/delay/{n}to validate timeout behavior and/status/{code}to validate retries. - Inspect the
istio-proxysidecar logs to observe timeout terminations and retry attempts.