如果我编写如下所示的 Gateway 和 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
Run Code Online (Sandbox Code Playgroud)
换句话说 - 如果我们忽略 DNS - 可以使用哪些“主机”标头通过集群/负载均衡器 IP 访问服务/部署?
回答你的问题
\n\n\n您是说“hosts”是否基于 HTTP“Host”标头?
\n
是的,它基于 http 主机标头。
\n根据 istio文档:
\n\n\n使用curl访问httpbin服务:
\n
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/status/200"\nHTTP/1.1 200 OK\nserver: istio-envoy\n...\nRun Code Online (Sandbox Code Playgroud)\n\n\n请注意,您使用 -H 标志将主机 HTTP 标头设置为 \xe2\x80\x9chttpbin.example.com\xe2\x80\x9d。这是必需的,因为您的入口网关配置为处理 \xe2\x80\x9chttpbin.example.com\xe2\x80\x9d,但在您的测试环境中,您没有该主机的 DNS 绑定,只是将请求发送到入口知识产权。
\n
我使用bookinfo 应用程序进行测试。
\nkubectl label namespace default istio-injection=enabled\nkubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml\nRun Code Online (Sandbox Code Playgroud)\n将虚拟服务hosts从更改*为example.com。
apiVersion: networking.istio.io/v1alpha3\nkind: Gateway\nmetadata:\n name: bookinfo-gateway\nspec:\n selector:\n istio: ingressgateway # use istio default controller\n servers:\n - port:\n number: 80\n name: http\n protocol: HTTP\n hosts:\n - "*"\n---\napiVersion: networking.istio.io/v1alpha3\nkind: VirtualService\nmetadata:\n name: bookinfo\nspec:\n hosts:\n - "example.com"\n gateways:\n - bookinfo-gateway\n http:\n - match:\n - uri:\n exact: /productpage\n - uri:\n prefix: /static\n - uri:\n exact: /login\n - uri:\n exact: /logout\n - uri:\n prefix: /api/v1/products\n route:\n - destination:\n host: productpage\n port:\n number: 9080\nRun Code Online (Sandbox Code Playgroud)\n用postman测试过,你也可以使用上面提到的curl。
\nexample.com 主机标头的示例 -> 状态 200。
\n\ncurl -v -HHost:example.com xx.xxx.xx.x/productpage\nHost:example.com\nHTTP/1.1 200 OK\nRun Code Online (Sandbox Code Playgroud)\nexample2.com 主机标头的示例 -> 状态 404。
\n\ncurl -v -HHost:example2.com xx.xxx.xx.x/productpage\nHost:example2.com\nHTTP/1.1 404 Not Found\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
994 次 |
| 最近记录: |