nginx ingress rate limiting

12/18/2020

i am not able to understand one point in the rate-limiting of Nginx ingress

i was referring to one article regarding rate limiting with nginx ingress : https://medium.com/titansoft-engineering/rate-limiting-for-your-kubernetes-applications-with-nginx-ingress-2e32721f7f57#:~:text=When%20we%20use%20NGINX%20ingress,configure%20rate%20limits%20with%20annotations.&text=As%20an%20example%20above%2C%20the,qps)%20on%20the%20Hello%20service.

in limitation section at last

It applies to the whole ingress and is not able to configure exceptions, eg. when you want to exclude a health check path /healthz from your service.

if i am creating two ingresses with different names, one has path /hello1 and another /hello2 both pointing to the same service backend.

Now if i am adding rate limiting to only one ingress or path /hello1 will it affect another? if the same host or domain is there ???

ingress 1 : example.com/hello1 - rate-limit set

ingress 2 : example.com/hello2 no rate limiting

Thanks in advance

-- chagan
docker
kubernetes
nginx
nginx-ingress

1 Answer

12/20/2020

Rate limit will be applied only to that ingress where you specified it. What is basically nginx-ingress doing in the background - it merges rules into 1 huge config, however they applies to different objects.

e.g 2 different ingresses for same host and diff path.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test1
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    nginx.ingress.kubernetes.io/limit-rps: '5'
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /path1
        backend:
          serviceName: service1
          servicePort: 8080

and

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test2
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    nginx.ingress.kubernetes.io/limit-rps: '10'
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /path2
        backend:
          serviceName: service1
          servicePort: 8080
-- Vit
Source: StackOverflow