1

I have a k8s service defined as type: LoadBalancer which sets an external LB. Can I identify on application level that an incoming request is routed from the LoadBlancer?

Are there any guaranteed http headers? Can I define custom headers for that service that would be added to all incoming requests?

Kludge
  • 2,653
  • 4
  • 20
  • 42
  • The headers it sets (x-forward-*) are commonly set by ingress controllers as well. Why both an ingress and a servicetype Loadbalancer? There is an ALB ingress that you can use – jordanm Apr 27 '20 at 17:46
  • I would like to distinguish incoming requests: which are from the LB (currently defined by service only) and which are from an internal ingress – Kludge Apr 27 '20 at 18:00
  • @jordanm - and regarding ALB, does it support all annotations of a regular LB? Or is it, like, ingress-controller? – Kludge Apr 27 '20 at 18:06

2 Answers2

1

If your internal ingress is using nginx as an ingress controller you can add a custom header that will indicate that.

Yaron Idan
  • 6,207
  • 5
  • 44
  • 66
  • I might use that if I don't find another solution, but I'm more interested in adding a custom header to requests from the LoadBalancer, if this is somehow possible. – Kludge Apr 27 '20 at 20:31
  • Plus, I didn't get how to add this nginx snippet into an ingress config file (?) – Kludge Apr 27 '20 at 21:27
  • This is an example for adding headers to an nginx ingress - https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers/. AFAIK there is no way to add custom headers to a request coming from elb, but you can ask open a support ticket for aws or ask in their developer forums. – Yaron Idan Apr 28 '20 at 11:11
  • 1
    Weird they do not support it out of the box. Anyways, meanwhile using your other suggestion with the internal ingress. תודה :) – Kludge Apr 28 '20 at 12:05
  • No problem. I don't think it's weird BTW. A load balancer is not the same as a web server, and it makes sense for it to not cover this functionality – Yaron Idan Apr 28 '20 at 14:43
0

ELB guide says that:

Application Load Balancers and Classic Load Balancers add X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Port headers to the request.

Have you already been trying using these ones?

Nick
  • 1,882
  • 11
  • 16
  • I read this doc. Since I'm trying to distinguish a LoadBalancer and an ingress controller (which is also LB), then I don't think I can rely on these headers. I was hoping for something more uniq, or, the ability to add custom headers – Kludge Apr 28 '20 at 12:10
  • @Kludge , am I right that Ingress handles traffic generated outside your VPC and 'LB Service' is used by hosts from vpc (basically EC2 instances) ? – Nick Apr 28 '20 at 13:03
  • no, the LB service actually acts as an external server. I would like to trace these incoming requests app-level – Kludge Apr 28 '20 at 13:28