1

I'm moving to kubernetes using traefik as my Ingress Controller.

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.

I can use the ingress.kubernetes.io/custom-request-headers 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.

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

stefanobaldo
  • 1,957
  • 6
  • 27
  • 40

1 Answers1

4

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

You can do it by Traefik:

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: /

Also, the same thing you can do by Nginx Ingress Controller.

It has the support for configuration snipper. Here is an example of using it to set a custom header per Ingress object:

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: /

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.

f_i
  • 3,084
  • 28
  • 31
Anton Kostenko
  • 8,200
  • 2
  • 30
  • 37
  • In your example, you're setting the same header for all rules, right? What I need is to set a different custom header for each rule. I don't think I can do that because I cannot make annotations inside the rules object. That said, my only option is to create one ingress per host (each ingress with a single host rule). I've created 3000+ ingresses with a single rule each with traefik as the controller and it's working, so I'm ok for now, but I'm afraid of that because I don't know if creating so many ingresses can be a problem or not. – stefanobaldo Mar 20 '18 at 02:19
  • Yep, you are right. I for some reason read Ingress as Ingress Controller in your question:( I will update an answer. – Anton Kostenko Mar 20 '18 at 07:44