How to use rate limit for a single api | Kong Ingress Controller | Rate Limit Plugin

Hi,

I am using Path and Host-Based Routing in the Kong ingress controller. Below is the sample file

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app1
namespace: app
annotations:
konghq.com/strip-path: “true”
kubernetes.io/ingress.class: kong
spec:
rules:

  • host: h1.example.com
    http:
    paths:
    • path: /api
      backend:
      serviceName: app1-service
      servicePort: 80

Requirement:

I want to apply a rate limit on a single API. i.e h1.example.com/api/v1.

The rest of the APIs should work as usual. i.e. No Rate limit for these endpoints. h1.example.com/api/v2 , /api/v3

Note: I am using strip path annotation in the ingress rule.

How can I achieve this using the Rate limit Plugin? Any help would be appreciated.

Hi Akshay,

You can follow the official doc and apply konghq.com/plugins: rate-limiting-plugin-name annotation to your ingress. That way the rate limiting plugin will only be applied on this ingress object which is the route.

@fomm Thanks for your response.

this is the only concern. rate limit plugin will be applied on every request with /api.

I want it to be applied only on /api/v1, not on /api/v2/register or /api/v3/login

Ingress doesn’t provide any way to add configuration for specific rules beyond the settings exposed by Ingress itself (effectively just the rule path and associated backend Service). Annotations, which are the only way to add vendor-specific configuration (such as Kong plugin configurations) must be configured at the Ingress level, and apply to all rules in that Ingress. You cannot apply them to a subset of an Ingress’s rules only.

As such, to apply that plugin to some rules and not others, you will need multiple Ingresses covering different paths in your application’s API. You’ll apply the rate limiting configuration only to the Ingress that contains rules you want to throttle.


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ