Mesh Timeout

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

TargetRef support matrix

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

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-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. to:
  10. - targetRef:
  11. kind: Mesh
  12. default:
  13. idleTimeout: 20s
  14. connectionTimeout: 2s
  15. http:
  16. requestTimeout: 2s
  1. type: MeshTimeout
  2. name: timeout-global
  3. mesh: default
  4. spec:
  5. to:
  6. - targetRef:
  7. kind: Mesh
  8. default:
  9. idleTimeout: 20s
  10. connectionTimeout: 2s
  11. http:
  12. requestTimeout: 2s

Simple TCP configuration

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

I am using MeshService

  1. type: MeshTimeout
  2. name: inbound-timeout
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. from:
  10. - targetRef:
  11. kind: Mesh
  12. default:
  13. idleTimeout: 60s
  14. connectionTimeout: 2s
  15. http:
  16. requestTimeout: 10s
  17. streamIdleTimeout: 1h
  18. maxStreamDuration: 30m
  19. maxConnectionDuration: 30m
  20. to:
  21. - targetRef:
  22. kind: MeshService
  23. name: backend
  24. default:
  25. idleTimeout: 60s
  26. connectionTimeout: 1s
  27. http:
  28. requestTimeout: 5s
  29. streamIdleTimeout: 1h
  30. maxStreamDuration: 30m
  31. maxConnectionDuration: 30m
  1. type: MeshTimeout
  2. name: inbound-timeout
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. from:
  10. - targetRef:
  11. kind: Mesh
  12. default:
  13. idleTimeout: 60s
  14. connectionTimeout: 2s
  15. http:
  16. requestTimeout: 10s
  17. streamIdleTimeout: 1h
  18. maxStreamDuration: 30m
  19. maxConnectionDuration: 30m
  20. to:
  21. - targetRef:
  22. kind: MeshService
  23. name: backend
  24. sectionName: http
  25. default:
  26. idleTimeout: 60s
  27. connectionTimeout: 1s
  28. http:
  29. requestTimeout: 5s
  30. streamIdleTimeout: 1h
  31. maxStreamDuration: 30m
  32. 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-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend_kuma-demo_svc_3001
  17. rules:
  18. - matches:
  19. - path:
  20. type: PathPrefix
  21. value: "/v2"
  22. default:
  23. backendRefs:
  24. - kind: MeshService
  25. name: backend-v2_kuma-demo_svc_3001
  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshHTTPRoute
  3. metadata:
  4. name: route-to-backend-v2
  5. namespace: kuma-demo
  6. labels:
  7. kuma.io/mesh: default
  8. spec:
  9. targetRef:
  10. kind: MeshSubset
  11. tags:
  12. app: frontend
  13. to:
  14. - targetRef:
  15. kind: MeshService
  16. name: backend
  17. namespace: kuma-demo
  18. sectionName: http
  19. rules:
  20. - matches:
  21. - path:
  22. type: PathPrefix
  23. value: "/v2"
  24. default:
  25. backendRefs:
  26. - kind: MeshService
  27. name: backend-v2
  28. namespace: kuma-demo
  29. port: 3001

I am using MeshService

  1. type: MeshHTTPRoute
  2. name: route-to-backend-v2
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. rules:
  14. - matches:
  15. - path:
  16. type: PathPrefix
  17. value: "/v2"
  18. default:
  19. backendRefs:
  20. - kind: MeshService
  21. name: backend-v2
  1. type: MeshHTTPRoute
  2. name: route-to-backend-v2
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshSubset
  7. tags:
  8. app: frontend
  9. to:
  10. - targetRef:
  11. kind: MeshService
  12. name: backend
  13. sectionName: http
  14. rules:
  15. - matches:
  16. - path:
  17. type: PathPrefix
  18. value: "/v2"
  19. default:
  20. backendRefs:
  21. - kind: MeshService
  22. name: backend-v2
  23. port: 3001

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-demo
  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