如何绕过指定“主机"标头,以访问由Ingress控制器指向的服务? [英] How to get around specifying "Host" header to access services pointed by Ingress controllers?
问题描述
我的入口控制器正在运行,并且我可以使用http://(externalIP)/path
使用来自RestClient的HTTP GET请求使用群集外的服务.但是,我必须为"Host"
标头指定value = "host"
(我的Ingress资源的值)才能正常工作.因此,我无法从Web浏览器中点击http://(externalIP)/path
.有什么方法可以使我能够从外部Web浏览器进行访问而不必在请求标头中指定"Host"
吗?
My ingress controller is working and I am able to access the service outside the cluster using http://(externalIP)/path
using an HTTP GET request from a RestClient. However, I had to specify the "Host"
header with value = "host"
(value of my Ingress Resource) for this to work. Because of this, I am not able to hit http://(externalIP)/path
from my web browser. Is there any way I can enable access from my external web browser without having to specify "Host"
in the request header?
入口资源:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
namespace: ingress-nginx
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: master1.saas.com
http:
paths:
- backend:
serviceName: gen-devops
servicePort: 10311
path: /*
入口服务:
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
- name: https
port: 443
targetPort: 443
protocol: TCP
externalIPs:
- 172.16.32.85
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
推荐答案
我假设您要使用它进行测试.
I assume you want to use this for testing.
如果您正在使用任何* nix风味操作系统(MacOS,Linux),则可以将条目添加到/etc/hosts
文件中,如下所示:
If you are using any *nix flavor OS (MacOS, Linux) you can add an entry to your /etc/hosts
file, something like this:
172.16.32.85 master1.saas.com
如果使用任何Windows框,都可以在C:\Windows\System32\Drivers\etc\hosts
If you are using any Windows box you can add the same entry in C:\Windows\System32\Drivers\etc\hosts
这篇关于如何绕过指定“主机"标头,以访问由Ingress控制器指向的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!