0

I have multiple services running inside a kubernetes cluster and all talking to each other. I want one of the services to have a rate limiting feature. This means that for certain caller ids it should accept only 50 calls per minute and reject all others with 429 "Too many requests". This limiting should happen for calls inside the same cluster.

Can this be done using k8 objects/features?

1

It is possible to use Circuit Breaker in istio (kubernetes addon), which can be achieved by creating traffic policy connection pools with istio destinationrule objects.

According to istio documentation:

Circuit breakers

Circuit breakers are another useful mechanism Istio provides for creating resilient microservice-based applications. In a circuit breaker, you set limits for calls to individual hosts within a service, such as the number of concurrent connections or how many times calls to this host have failed. Once that limit has been reached the circuit breaker “trips” and stops further connections to that host. Using a circuit breaker pattern enables fast failure rather than clients trying to connect to an overloaded or failing host.

As circuit breaking applies to “real” mesh destinations in a load balancing pool, you configure circuit breaker thresholds in destination rules, with the settings applying to each individual host in the service. The following example limits the number of concurrent connections for the reviews service workloads of the v1 subset to 100:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: reviews
spec:
  host: reviews
  subsets:
  - name: v1
    labels:
      version: v1
    trafficPolicy:
      connectionPool:
        tcp:
          maxConnections: 100

You can find out more about creating circuit breakers in Circuit Breaking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.