Mesh Timeout

This policy uses new policy matching algorithm. Do not combine with Timeout policy.

TargetRef support matrix

targetRefAllowed kinds
targetRef.kindMesh, MeshSubset, MeshService, MeshServiceSubset, MeshHTTPRoute
to[].targetRef.kindMesh, MeshService
from[].targetRef.kindMesh
targetRefAllowed kinds
targetRef.kindMesh, MeshGateway, MeshGateway with listener tags
to[].targetRef.kindMesh
from[].targetRef.kindMesh
targetRefAllowed kinds
targetRef.kindMesh, MeshSubset, MeshService, MeshServiceSubset, MeshHTTPRoute
to[].targetRef.kindMesh, MeshService

To learn more about the information in this table, see the matching docs.

Configuration

This policy enables Kuma to set timeouts on the inbound and outbound connections depending on the protocol. Using this policy you can configure TCP and HTTP timeouts. Timeout configuration is split into two sections: common configuration and HTTP configuration. Common config is applied to both HTTP and TCP communication. HTTP timeout are only applied when service is marked as http. More on this in protocol support section.

MeshTimeout policy lets you configure multiple timeouts:

  • connectionTimeout
  • idleTimeout
  • http requestTimeout
  • http streamIdleTimeout
  • http maxStreamDuration
  • http maxConnectionDuration- http requestHeadersTimeout

    Timeouts explained

Connection timeout

Connection timeout specifies the amount of time DP will wait for a TCP connection to be established.

Idle timeout

For TCP connections idle timeout is the amount of time that the DP will allow a connection to exist with no inbound or outbound activity. On the other hand when connection in HTTP time at which an inbound or outbound connection will be terminated if there are no active streams

HTTP request timeout

Request timeout lets you configure how long the data plane proxy should wait for the full response. In details, it spans between the point at which the entire request has been processed by DP and when the response has been completely processed by DP.

HTTP stream idle timeout

Stream idle timeout is the amount of time that the data plane proxy will allow an HTTP/2 stream to exist with no inbound or outbound activity. This timeout is strongly recommended for all requests (not just streaming requests/responses) as it additionally defends against a peer that does not open the stream window once an entire response has been buffered to be sent to a downstream client.

Stream timeouts apply even when you are only using HTTP/1.1 in you services. This is because every connection between data plane proxies is upgraded to HTTP/2.

HTTP max stream duration

Max stream duration is the maximum time that a stream’s lifetime will span. You can use this functionality when you want to reset HTTP request/response streams periodically.

HTTP max connection duration

Max connection duration is the time after which an inbound or outbound connection will be drained and/or closed, starting from when it was first established. If there are no active streams, the connection will be closed. If there are any active streams, the drain sequence will kick-in, and the connection will be force-closed after 5 seconds.

HTTP request headers timeout

The amount of time that proxy will wait for the request headers to be received. The timer is activated when the first byte of the headers is received, and is disarmed when the last byte of the headers has been received.

Examples

Simple outbound HTTP configuration

This configuration will be applied to all data plane proxies inside of Mesh.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTimeout
  3. metadata:
  4. name: timeout-global
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: Mesh
  11. to:
  12. - targetRef:
  13. kind: Mesh
  14. default:
  15. idleTimeout: 20s
  16. connectionTimeout: 2s
  17. http:
  18. requestTimeout: 2s
  1. type: MeshTimeout
  2. name: timeout-global
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: Mesh
  7. to:
  8. - targetRef:
  9. kind: Mesh
  10. default:
  11. idleTimeout: 20s
  12. connectionTimeout: 2s
  13. http:
  14. requestTimeout: 2s

Simple TCP configuration

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTimeout
  3. metadata:
  4. name: tcp-timeout
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: Mesh
  11. to:
  12. - targetRef:
  13. kind: Mesh
  14. default:
  15. idleTimeout: 20s
  16. connectionTimeout: 2s
  1. type: MeshTimeout
  2. name: tcp-timeout
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: Mesh
  7. to:
  8. - targetRef:
  9. kind: Mesh
  10. default:
  11. idleTimeout: 20s
  12. connectionTimeout: 2s

Simple configuration for inbound applied to specific service

This configuration will be applied to backend service inbound.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTimeout
  3. metadata:
  4. name: inbound-timeout
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshService
  11. name: backend
  12. from:
  13. - targetRef:
  14. kind: Mesh
  15. default:
  16. idleTimeout: 20s
  17. connectionTimeout: 2s
  1. type: MeshTimeout
  2. name: inbound-timeout
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: backend
  8. from:
  9. - targetRef:
  10. kind: Mesh
  11. default:
  12. idleTimeout: 20s
  13. connectionTimeout: 2s

Full config applied to inbound and outbound of specific service

This timeout configuration will be applied to all inbound connections to frontend and outbound connections from frontend to backend service

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTimeout
  3. metadata:
  4. name: inbound-timeout
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshService
  11. name: frontend_kuma-demo_svc_8080
  12. from:
  13. - targetRef:
  14. kind: Mesh
  15. default:
  16. idleTimeout: 60s
  17. connectionTimeout: 2s
  18. http:
  19. requestTimeout: 10s
  20. streamIdleTimeout: 1h
  21. maxStreamDuration: 30m
  22. maxConnectionDuration: 30m
  23. to:
  24. - targetRef:
  25. kind: MeshService
  26. name: backend_kuma-demo_svc_3001
  27. default:
  28. idleTimeout: 60s
  29. connectionTimeout: 1s
  30. http:
  31. requestTimeout: 5s
  32. streamIdleTimeout: 1h
  33. maxStreamDuration: 30m
  34. maxConnectionDuration: 30m
  1. type: MeshTimeout
  2. name: inbound-timeout
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: frontend
  8. from:
  9. - targetRef:
  10. kind: Mesh
  11. default:
  12. idleTimeout: 60s
  13. connectionTimeout: 2s
  14. http:
  15. requestTimeout: 10s
  16. streamIdleTimeout: 1h
  17. maxStreamDuration: 30m
  18. maxConnectionDuration: 30m
  19. to:
  20. - targetRef:
  21. kind: MeshService
  22. name: backend
  23. default:
  24. idleTimeout: 60s
  25. connectionTimeout: 1s
  26. http:
  27. requestTimeout: 5s
  28. streamIdleTimeout: 1h
  29. maxStreamDuration: 30m
  30. maxConnectionDuration: 30m

Target MeshHTTPRoute

Timeouts like http.requestTimeout and http.streamIdleTimeout are configurable per route. If a MeshHTTPRoute creates routes on the outbound listener of the service then MeshTimeout policy can configure timeouts on these routes.

In the following example the MeshHTTPRoute policy route-to-backend-v2 redirects all requests to /v2* to backend instances with version: v2 tag. MeshTimeout backend-v2 configures timeouts only for requests that are going through route-to-backend-v2 route.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshHTTPRoute
  3. metadata:
  4. name: route-to-backend-v2
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshService
  11. name: frontend_kuma-demo_svc_8080
  12. to:
  13. - targetRef:
  14. kind: MeshService
  15. name: backend_kuma-demo_svc_3001
  16. rules:
  17. - matches:
  18. - path:
  19. type: PathPrefix
  20. value: "/v2"
  21. default:
  22. backendRefs:
  23. - kind: MeshServiceSubset
  24. tags:
  25. version: v2
  26. name: backend_kuma-demo_svc_3001
  1. type: MeshHTTPRoute
  2. name: route-to-backend-v2
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: frontend
  8. to:
  9. - targetRef:
  10. kind: MeshService
  11. name: backend_kuma-demo_svc_3001
  12. rules:
  13. - matches:
  14. - path:
  15. type: PathPrefix
  16. value: "/v2"
  17. default:
  18. backendRefs:
  19. - kind: MeshServiceSubset
  20. tags:
  21. version: v2
  22. name: backend

You can see in the following route that the top level targetRef matches the previously defined MeshHTTPRoute.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTimeout
  3. metadata:
  4. name: backend-v2
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshHTTPRoute
  11. name: route-to-backend-v2
  12. to:
  13. - targetRef:
  14. kind: Mesh
  15. default:
  16. http:
  17. requestTimeout: 5s
  18. streamIdleTimeout: 1h
  1. type: MeshTimeout
  2. name: backend-v2
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshHTTPRoute
  7. name: route-to-backend-v2
  8. to:
  9. - targetRef:
  10. kind: Mesh
  11. default:
  12. http:
  13. requestTimeout: 5s
  14. streamIdleTimeout: 1h

Default configuration for all gateways in the Mesh

This configuration will be applied on inbounds and outbounds of all gateways.

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTimeout
  3. metadata:
  4. name: mesh-gateways-timeout-all-default
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: Mesh
  11. proxyTypes:
  12. - Gateway
  13. from:
  14. - targetRef:
  15. kind: Mesh
  16. default:
  17. idleTimeout: 5m
  18. http:
  19. streamIdleTimeout: 5s
  20. requestHeadersTimeout: 500ms
  21. to:
  22. - targetRef:
  23. kind: Mesh
  24. default:
  25. idleTimeout: 1h
  26. http:
  27. streamIdleTimeout: 5s
  1. type: MeshTimeout
  2. name: mesh-gateways-timeout-all-default
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: Mesh
  7. proxyTypes:
  8. - Gateway
  9. from:
  10. - targetRef:
  11. kind: Mesh
  12. default:
  13. idleTimeout: 5m
  14. http:
  15. streamIdleTimeout: 5s
  16. requestHeadersTimeout: 500ms
  17. to:
  18. - targetRef:
  19. kind: Mesh
  20. default:
  21. idleTimeout: 1h
  22. http:
  23. streamIdleTimeout: 5s

Defaults

Propertydefault   
idleTimeout1h   
connectionTimeout5s   
http.requestTimeout15s   
http.streamIdleTimeout30m   
http.maxStreamDuration0s   
http.maxConnectionDuration0s http.requestHeadersTimeout0s

All policy options