<p>Is it possible to rate limit requests based on HTTP header value on nginx-ingress?</p>

<p>As I didn't have kubernetes nginx ingress from nginxinc suggested solution here didn't work. </p>

<p>Manage to do it through configmap and annotation tweak.</p>

<p><strong>Configmap:</strong></p>

<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: ingress-nginx
  labels:
    app: nginx-ingress
    chart: nginx-ingress-1.33.0-dev
    release: nginx-ingress
data:
  http-snippet: |
    limit_req_zone $http_authorization zone=my-zone:20m rate=5r/s;
    limit_req_zone $binary_remote_addr zone=my-zone:20m rate=10r/s;
    limit_req_zone $http_someheader zone=my-zone:20m rate=20r/s;
</code></pre>

<p><strong>Annotation in ingress resource:</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/configuration-snippet: |
      limit_req zone=my-zone-1 burst=10 nodelay;
      limit_req_log_level notice;
      limit_req_status 429;
</code></pre>

<p><em>Note: http-snippet is not allowed as annotation!</em></p>

<p><strong>Example with different throtling for different locations defined by one ingress:</strong></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/server-snippet: |
      location /content/images/ {
      limit_req zone=my-zone-2 burst=50 nodelay;
      }
      location /content/texts/ {
      limit_req zone=my-zone-3 burst=50 nodelay;
      }
    nginx.ingress.kubernetes.io/configuration-snippet: |
      limit_req zone=my-zone-1 burst=10 nodelay;
      limit_req_log_level notice;
      limit_req_status 429;
</code></pre>

<p><em>Note that defining location here in <strong>server-snippet</strong> annotation doesn't allow you to define it further down in ingress</em></p>
