由于某些遗留应用程序依赖Host头来正常运行,我需要一个能够重写Host头并将其传递给下游(后端)的Ingress(代理等)。是否有任何支持此功能的Ingress控制器?
例:
最终用户通过foo.com/a
访问我们的网站,后端a
和foo.com/b
用于后端b
。但由于a
和b
是遗留应用程序,它只接受:
a
时,Host: a.foo.com
接受连接b
时,Host: b.foo.com
接受连接这可以使用此注释来完成:nginx.ingress.kubernetes.io/upstream-vhost: host.example.com
我不确定您是否可以在NGINX Ingress Controller中找到适当的注释,以便主机头修改以符合您的要求。但是,您可以考虑使用nginx.ingress.kubernetes.io/configuration-snippet
annotation将配置代码段附加到特定Nginx控制器窗格的nginx.conf
内的位置块:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header Host www.example-host.com;
name: my-app
spec:
rules:
- host: my-app.example.com
http:
paths:
- backend:
path: /app
serviceName: my-app
servicePort: http
我们在这里设置主机头www.example-host.com
为目标URL my-app.example.com
。
我想把我的发现添加到我的这个问题中。
虽然我的解决方案不使用k8s Ingress Controller,但是我们的集群正在使用Istio和Istio的VirtualService支持重写uri
和authority
(主机头),如以下链接所示:https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPRewrite
要了解我如何在我的情况下实现这一点,你可以看一下这个链接:https://github.com/istio/istio/issues/11668
您可以在kubernetes上使用入口nginx控制器并设置head并将transer转发到后端并管理来自入口对象的服务连接。
这里从头部共享重写目标的链接。
https://kubernetes.github.io/ingress-nginx/examples/rewrite/
ings nginx对ssl证书管理员也很好,你可以添加它。
使用入口注释管理其他事物。
检查入口SSl设置,你可以根据需要修改它
https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes
进入将会像最后一样
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- hosts:
- myapp.abc.com
secretName: ingress-tls
rules:
- host: myapp.abc.com
http:
paths:
- path: /my-service
backend:
serviceName: my-backend
servicePort: 80