Rate-limit on specific subpath

In traefik 1.7.x, is it possible to add ratelimit on a specific subpath, and nowhere else?

for example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/rate-limit: |
      extractorfunc: client.ip
      rateset:
        api-rateset:
          period: 60s
          average: 10
          burst: 20
  name: REDACTED
  namespace: REDACTED
spec:
  rules:
  - host: REDACTED
    http:
      paths:
      - backend:
          serviceName: REDACTED
          servicePort: REDACTED

I want the ratelimit to apply only on

- backend:
          serviceName: REDACTED/HERE/SOMEWHERE/ONLY

Hello @recet, I'm not totally sure, but does it work by defining 2 ingress rules?
The goal is to separate concern: you define the most specific ingress rul to be your (host(REDACTED) + pathprefix(/HERE/SOMEWHERE/ONLY)),
which is under rate limiting control,
and then define a second ingress rule for the rest the host REDACTED.

This should work because the priority of matching rules in Traefik v1.7 are based on the lenght of the rule. so (host + path) has more priority than (host), making the expected behavior. Reference: https://docs.traefik.io/v1.7/basics/#priorities.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/rate-limit: |
      extractorfunc: client.ip
      rateset:
        api-rateset:
          period: 60s
          average: 10
          burst: 20
  name: REDACTED
  namespace: REDACTED
spec:
  rules:
  - host: REDACTED
    http:
      paths:
      - path: /HERE/SOMEWHERE/ONLY
        backend:
          serviceName: REDACTED
          servicePort: REDACTED

and

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
  name: REDACTED-2
  namespace: REDACTED
spec:
  rules:
  - host: REDACTED
    http:
      paths:
      - backend:
          serviceName: REDACTED
          servicePort: REDACTED

Let us know if it is ok?

Thanks @dduportal. That works!

1 Like