One k8s hostname issue

Recently got an issue on k8s. The detail is:

  1. Login to https://abc.com
  2. After login, the expected is that the URL will be redirected to https://abc.com/home however, it is wrongly redirected to the internal name of the hostname abc.com, like https://abc-internal.com/home

​ Initially I thought that this is an easy issue which is caused by the headers is not forwarded from k8s ingress to the service, including the headers of

  • Host

  • X-Forwarded-For

    But after some logs, these headers are totally correct.

And finally by comparing the request/response dumps inside k8s and outside k8s, we found that this issue is not happening when the k8s ingress process the request; however it happens when ingress process the Response.

When It processes the Response, it REWRITE the 302 Location header from the correct value to the wrong value.

To Fix, just set the correct value for Nginx Ingress Controller, for

1
2
3
4
5
6
metadata:
annotations:
kubernetes.io/ingress.class: nginx-ingress
....
nginx.ingress.kubernetes.io/proxy-redirect-from: https://abc-internal.com
nginx.ingress.kubernetes.io/proxy-redirect-to: https://abc.com

And issue fixed.