kubernetes - VirtualService 和 Gateway 中的“hosts”属性是否基于 HTTP 的 Host 标头(第 7 层)?
问题描述
如果我编写如下所示的 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
换一种说法 - 如果我们忽略 DNS - 可以使用哪些“主机”标头通过集群/负载平衡器 IP 访问服务/部署?
解决方案
如果您可以使用任何 dns 或集群/负载均衡器 IP 访问集群,则可以将 example.com DNS 更改为 *. 或其他方法将所有 DNS 像列表一样放在hosts块中。
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
在上面的示例中,您可以从任何主机标头访问,但匹配不同服务的标准是http 匹配中的 uri 块
我希望这个对你有用。:)
推荐阅读
- arrays - 为什么 IF 数组公式不生成数组?
- spring-boot - Spring 5 WebFlux 服务器通过 RSocket 协议推送通知
- haskell - 根据条件对列表进行分区的功能 - Haskell
- ajax - 阻止对服务器上我的系统 Web 应用程序文件的访问
- c++ - 为什么 sleep() 会导致换行?
- php - 使用 cURL 将表单数据发布到服务器
- python - 高斯过程回归(克里金法)与径向基函数插值
- batch-file - cmd中的for循环命令有问题
- python - 如何在调用更新后端状态的函数时从 python (fastapi) 发送服务器端事件
- open-policy-agent - 将 OPA Rego 限制为单一规则解决方案