<p>Is it possible to configure an ingress controller in Kubernetes to route the HTTP requests to a service only if the incoming requests have a certain value for a header?</p>

<p>Example</p>

<p>An HTTP request with following header</p>

<pre><code>X-MY-CUSTOM-HEADER: accepted-value
</code></pre>

<p>should be forwarded to service1</p>

<p>An HTTP request with following header</p>

<pre><code>X-MY-CUSTOM-HEADER: invalid-value
</code></pre>

<p>should be blocked</p>

<p>If is possible could you detail a bit or point to some documentation as I wasn't able to find documentation for such usecase </p>

<p>If you are using an nginx ingress controller you can do it with a <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#configuration-snippet" rel="nofollow noreferrer">Configuration snippet</a> annotation. Then you can add something like this:</p>

<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  map $http_x_custom_header $not_ok {
      default "1";
      Value1  "0";
      Value2  "0";
      Value3  "0";
  }

  if ($not_ok) {
      return 403; 
  }
</code></pre>

<p>Some more info <a href="https://stackoverflow.com/a/18972508/2989261">here</a>.</p>
