gpt4 book ai didi

kubernetes - VirtualService 和 Gateway 中的 "hosts"属性是否基于 HTTP 的 Host header (第 7 层)?

转载 作者:行者123 更新时间:2023-12-03 16:32:22 25 4
gpt4 key购买 nike

如果我编写如下所示的 Gateway 和 VirtualService 条目,主机属性匹配什么标准来确定是否应将传入请求路由到服务?它是 HTTP 请求中的“主机” header ,还是其他什么?

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 - 可以使用哪些“主机” header 通过集群/负载均衡器 IP 访问服务/部署?

最佳答案

如果您可以使用任何 dns 或集群/负载均衡器 IP 访问集群,则可以将 example.com DNS 更改为 *.或其他方法将所有 DNS 像列表一样放入 主机堵塞。

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 块
我希望这个对你有用。 :)

关于kubernetes - VirtualService 和 Gateway 中的 "hosts"属性是否基于 HTTP 的 Host header (第 7 层)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64655158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com