Using Traefik to apply a ratelimit to a subpath in kubernetes

6/19/2018

How do I use the Traefik ingress controller to apply a ratelimit to just a subpath, while serving up the service at the root /?

For example I have a service called my-webapp and I want to serve it under / but ratelimit /api/. I tried creating an ingress with the rules:

- host: my-webapp.io
  http:
    paths:
    - backend:
        serviceName: my-webapp
        servicePort: 80
      path: /api/

and the annotations:

traefik.ingress.kubernetes.io/rate-limit: |
      extractorfunc: client.ip
      rateset:
        api-rateset:
          period: 1s
          average: 10
          burst: 20

as well as an ingress with the path / hoping that the more specific ingress would take priority for the /api/ path, but it doesn't seem to be the case.

-- ocf1
kubernetes
kubernetes-ingress
traefik

1 Answer

6/19/2018

After investigating by adding a custom response header to each ingress to determine which ingress was used, I figured out the /api/ ingress does take priority. Applying ratelimits to this ingress and not the broader one appears to work, I'm not sure why it wasn't working earlier.

-- ocf1
Source: StackOverflow