<p>I'm moving to <code>kubernetes</code> using <code>traefik</code> as my Ingress Controller.</p>

<p>I have a single backend that should respond to 3000+ websites. Depending on the host, I need to add a custom header to the request before proxy passing it to the backend.</p>

<p>I can use the <code>ingress.kubernetes.io/custom-request-headers</code> annotation to add a custom header to the request but it's an annotation for the whole Ingress, so I would need to create 3000+ Ingresses, one for each website.</p>

<p>Is there another way to do this? Creating 3000+ Ingresses is the same thing as creating one Ingress with 3000+ rules?</p>

<p>Yes, you need to create one Ingress object per one host, if you want different headers her host.</p>

<p>You can do it by Traefik:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: traeffic-custom-request-header
  annotations:
    ingress.kubernetes.io/custom-request-headers: "mycustomheader: myheadervalue"
spec:
  rules:
  - host: custom.configuration.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /
</code></pre>

<p>Also, the same thing you can do by <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">Nginx</a> Ingress Controller.</p>

<p>It has the support for <code>configuration snipper</code>. <a href="https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/customization/configuration-snippets/ingress.yaml" rel="nofollow noreferrer">Here</a> is an example of using it to set a custom header per Ingress object:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-configuration-snippet
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Request-Id: $request_id";
spec:
  rules:
  - host: custom.configuration.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /
</code></pre>

<p>BTW, you can use several different ingress controllers on your cluster, so it does not need to migrate everything to only one type of Ingress.</p>
