Is it possible to rewrite HOST header in k8s Ingress Controller?
This can be done using this annotation: nginx.ingress.kubernetes.io/upstream-vhost: host.example.com
I'm not sure whether you can find appropriate annotation within NGINX Ingress Controller for Host header modification to match your requirement as well. However, you can consider using nginx.ingress.kubernetes.io/configuration-snippet
annotation in order to append configuration snippet to the location block inside nginx.conf
of the particular Nginx controller pod:
apiVersion: extensions/v1beta1kind: Ingressmetadata: annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/configuration-snippet: | proxy_set_header Host www.example-host.com; name: my-appspec: rules: - host: my-app.example.com http: paths: - backend: path: /app serviceName: my-app servicePort: http
We set here Host header www.example-host.com
for target URL my-app.example.com
.
I want to add my finding to this question of mine.
Although my solution is not using k8s Ingress Controller, our cluster is using Istio and Istio's VirtualService supports rewrite the uri
and authority
(Host header) as documented in this link: https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPRewrite
To know how I implement that in my case, you can take a look at this link: https://github.com/istio/istio/issues/11668