如果像下面这样编写网关和VirtualService条目,那么主机属性匹配哪些标准来确定是否应该将传入请求路由到服务?它是HTTP请求中的“主机”头,还是其他什么东西?
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: default-gateway
namespace: web
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- example.com
port:
name: www
number: 80
protocol: HTTP
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: web
namespace: web
spec:
gateways:
- default-gateway
hosts:
- example.com
http:
- route:
- destination:
host: webserver # assume this is the name of the Service for our deployed container
---
# Assume a Service and Deployment exist for the above Service另一种方法--如果我们忽略DNS --通过集群/负载均衡器IP可以使用什么“主机”报头来访问服务/部署?
发布于 2020-12-18 20:55:20
回答你的问题
您是说“主机”是基于还是不基于HTTP“主机”头?
是的,它基于http主机头。
根据istio 文档
使用curl访问httpbin服务:
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/status/200"
HTTP/1.1 200 OK
server: istio-envoy
...注意,您使用-H标志来,将HTTP头设置为“httpbin.example.com”。这是必要的,因为您的入口网关被配置为处理“httpbin.example.com”,但是在您的测试环境中,您对该主机没有DNS绑定,只是将请求发送到入口IP。
我使用bookinfo应用进行测试。
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml将虚拟服务hosts从*更改为example.com。
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "example.com"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080使用邮递员测试它,您也可以使用上面提到的curl。
example.com主机头->状态200的示例。

curl -v -HHost:example.com xx.xxx.xx.x/productpage
Host:example.com
HTTP/1.1 200 OK示例使用example2.com主机头->状态404。

curl -v -HHost:example2.com xx.xxx.xx.x/productpage
Host:example2.com
HTTP/1.1 404 Not Found发布于 2020-11-03 01:41:18
如果可以使用任何dns或集群/负载均衡器IP访问群集,则可以将example.com DNS更改为*。或者其他方法像列表一样将所有的DNSs放到主机块中。
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: default-gateway
namespace: web
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- '*'
port:
name: www
number: 80
protocol: HTTP
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: web
namespace: web
spec:
gateways:
- default-gateway
hosts:
- '*'
http:
- route:
- destination:
host: webserver # assume this is the name of the Service for our deployed container
---
# Assume a Service and Deployment exist for the above Service如果只使用一个外部DNS部署多个服务,则需要使用uri块进行匹配,例如,在虚拟服务中可以放置:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: web
namespace: web
spec:
gateways:
- default-gateway
hosts:
- '*'
http:
- match:
- uri:
prefix: /test/service1
rewrite:
uri: /
- route:
- destination:
host: webserver # assume this is the name of the Service for our deployed container在上面的示例中,您可以从任何主机头访问,但是要匹配到diferentes服务的criterio是http匹配中的uri块。
我希望它对你有用。:)
https://stackoverflow.com/questions/64655158
复制相似问题