<p>I am using Kubernetes Kops. I want to set rate limit rps at Ingress-Nginx level for a specific path only. </p>

<p>I know about </p>

<pre><code>nginx.ingress.kubernetes.io/limit-rps 
</code></pre>

<p>If I set this in Ingress rules then it will be applicable for all the routes. But, I want to apply it for a specific route. Let's say, when I am trying to access </p>

<pre><code>/login
</code></pre>

<p>I want to set rps limit to 100 for the path /login</p>

<pre><code>nginx.ingress.kubernetes.io/limit-rps: 100
</code></pre>

<p>This is my Ingress rules config,</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: staging-ingress-rules
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
spec:
  rules:
  - host: staging.mysite.com
    http:
      paths:
      - path: /login
        backend:
          serviceName: login_site
          servicePort: 80
      - path: /registration
        backend:
          serviceName: registration_site
          servicePort: 80
</code></pre>

cyberoy
<p>It's possible to slightly abuse the config for ingress-nginx by adding multiple Ingress definitions for the same hostname. ingress-nginx will merge the rules/routes together. The config will become harder to manage though and you are getting towards the limits of what nginx proxying can do for you.</p>

<h3>Other options</h3>

<p>Traefik has a <a href="https://docs.traefik.io/v2.0/middlewares/ratelimit/" rel="noreferrer">rate limit middleware</a> that can be applied to <a href="https://docs.traefik.io/v2.0/middlewares/overview/" rel="noreferrer">routes</a>.</p>

<p>Also look at something like <a href="https://docs.konghq.com/hub/kong-inc/rate-limiting/" rel="noreferrer">kong</a> or <a href="https://istio.io/docs/tasks/policy-enforcement/rate-limiting/" rel="noreferrer">istio</a> if you want to start managing individual services with more detail. </p>

<h3>Nginx Ingress config</h3>

<p>Creating a structure to your naming conventions will be important here so you know which Ingress houses which routes. Using the route path in the Ingress <code>name</code> is the where I would start but your use case may vary:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: staging-ingress-rules-registration
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
    nginx.ingress.kubernetes.io/limit-rps: '10'
spec:
  rules:
  - host: staging.mysite.com
    http:
      paths:
      - path: /registration
        backend:
          serviceName: registration-site
          servicePort: 80
</code></pre>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: staging-ingress-rules-login
  annotations:
    kubernetes.io/ingress.class: 'nginx'
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
    nginx.ingress.kubernetes.io/limit-rps: '100'
spec:
  rules:
  - host: staging.mysite.com
    http:
      paths:
      - path: /login
        backend:
          serviceName: login-site
          servicePort: 80
</code></pre>

<p>I'm not sure how host wide or server wide annotations (like <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#ssl-ciphers" rel="noreferrer"><code>nginx.ingress.kubernetes.io/ssl-ciphers</code></a>) would need to be managed. If they all merge nicely then maybe create a special Ingress just to house those. If not you might end up managing host settings across all Ingress configs which will be a pain. </p>
