MeshRateLimit (beta)

This policy uses new policy matching algorithm and is in beta state, it shouldn’t be mixed with Rate Limit.

This policy enables per-instance service request limiting. Policy supports ratelimiting of HTTP/HTTP2 requests and TCP connections.

The MeshRateLimit policy leverages Envoy’s local rate limiting for HTTP/HTTP2 and local rate limit filter for TCP connections.

You can configure:

  • how many HTTP requests are allowed in a specified time period
  • how the HTTP service responds when the limit is reached
  • how many TCP connections are allowed in a specified time period

The policy is applied per service instance. This means that if a service backend has 3 instances rate limited to 100 requests per second, the overall service rate limit is 300 requests per second.

Rate limiting supports an ExternalService only when ZoneEgress is enabled.

TargetRef support matrix

TargetRef typetop leveltofrom
Mesh
MeshSubset
MeshService
MeshServiceSubset
MeshGatewayRoute

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

Configuration

The MeshRateLimit policy supports both L4/TCP and L7/HTTP limiting. Envoy implements Token Bucket algorithm for rate limiting.

HTTP Rate limiting

  • disabled - (optional) - should rate limiting policy be disabled
  • requestRate - configuration of the number of requests in the specific time window
    • num - the number of requests to limit
    • interval - the interval for which requests will be limited
  • onRateLimit (optional) - actions to take on RateLimit event
    • status (optional) - the status code to return, defaults to 429
    • headers - (optional) headers which should be added to every rate limited response

Headers

  • set - (optional) - list of headers to set. Overrides value if the header exists.
    • name - header’s name
    • value - header’s value
  • add - (optional) - list of headers to add. Appends value if the header exists.
    • name - header’s name
    • value - header’s value

TCP Rate limiting

TCP rate limiting allows the configuration of a number of connections in the specific time window

  • disabled - (optional) - should rate limiting policy be disabled
  • connectionRate - configuration of the number of connections in the specific time window
    • num - the number of requests to limit
    • interval - the interval for which connections will be limited

Examples

HTTP Rate limit configured for service backend from all services in the Mesh

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRateLimit
  3. metadata:
  4. name: backend-rate-limit
  5. namespace: kuma-system
  6. spec:
  7. targetRef:
  8. kind: MeshService
  9. name: backend
  10. from:
  11. - targetRef:
  12. kind: Mesh
  13. default:
  14. local:
  15. http:
  16. requestRate:
  17. num: 5
  18. interval: 10s
  19. onRateLimit:
  20. status: 423
  21. headers:
  22. set:
  23. - name: "x-kuma-rate-limited"
  24. value: "true"

We will apply the configuration with kubectl apply -f [..].

  1. type: MeshRateLimit
  2. mesh: default
  3. name: backend-rate-limit
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: backend
  8. from:
  9. - targetRef:
  10. kind: Mesh
  11. default:
  12. local:
  13. http:
  14. requestRate:
  15. num: 5
  16. interval: 10s
  17. onRateLimit:
  18. status: 423
  19. headers:
  20. set:
  21. - name: "x-kuma-rate-limited"
  22. value: "true"

We will apply the configuration with kumactl apply -f [..] or via the HTTP API.

TCP rate limit for service backend from all services in the Mesh

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshRateLimit
  3. metadata:
  4. name: backend-rate-limit
  5. namespace: kuma-system
  6. spec:
  7. targetRef:
  8. kind: MeshService
  9. name: backend
  10. from:
  11. - targetRef:
  12. kind: Mesh
  13. default:
  14. local:
  15. tcp:
  16. connectionRate:
  17. num: 5
  18. interval: 10s

We will apply the configuration with kubectl apply -f [..].

  1. type: MeshRateLimit
  2. name: backend-rate-limit
  3. mesh: default
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: backend
  8. from:
  9. - targetRef:
  10. kind: Mesh
  11. default:
  12. local:
  13. tcp:
  14. connectionRate:
  15. num: 5
  16. interval: 10s

We will apply the configuration with kumactl apply -f [..] or via the HTTP API.