Istio 和 HTTP 主机 header
Istio and the HTTP Host header
我有一种情况,我不确定我是否做错了什么,或者 Istio 是否完全不支持该用例。这是我的设置:
我有一个 VirtualService
连接到一个 Gateway
使一些 API 外部可用,例如作为 api1.example.com
。 VirtualService
连接到执行某些请求预处理(某些条件 URL 重写)的某些 Service
。现在是棘手的部分:服务应该将请求转发到某个 API 管理解决方案,该解决方案在同一集群上,在不同的命名空间中 运行,并且 没有 启用 Istio。这通常有效,但我有一些额外的要求困扰着我。 API 管理需要知道请求最初发送到哪个端点(以应用正确的规则),因此当我将请求从我的服务转发到 API 管理 pod 时,HTTP Host
header 应该仍然是 api1.example.com
。这是它中断的地方,我只收到 502 Bad Gateway
个错误。
现在这是完整的设置,但我认为您可以将其归结为以下设置(不幸的是,我目前无法访问我可以创建和测试一些最小工作示例的某些集群):
pod1
在 namespace1
中运行并启用 Istio
pod2
在禁用 Istio 的情况下在 namespace2
中运行并公开为 service2
现在来自pod1
以下作品:
wget -qO- http://service2.namespace2.svc.cluster.local
但以下不是:
wget -qO- --header 'Host: api1.example.com' http://service2.namespace2.svc.cluster.local
非常感谢任何帮助或提示!
针对提出的问题进行了一些更新:
- Istio 版本为 1.4.6
- 当我执行
wget -qO- http://service2.namespace2.svc.cluster.local
时 pod2
收到请求,当我读取 Host
header 时它是 service2.namespace2.svc.cluster.local
- 当我执行
wget -qO- --header 'Host: api1.example.com' http://service2.namespace2.svc.cluster.local
时,请求根本不会到达 pod2
istioctl proxy-config listeners pod1
显示如下(pod1中的服务是运行在1024端口,pod2中的是运行在80端口)
ADDRESS PORT TYPE
100.96.4.131 1024 HTTP
100.96.4.131 15020 TCP
100.69.164.43 443 TCP
10.250.0.42 10250 TCP
10.250.0.47 10250 TCP
100.64.124.217 443 TCP
100.67.245.255 15011 TCP
10.250.0.46 10250 TCP
10.250.0.48 10250 TCP
10.250.0.9 10250 TCP
10.250.0.24 10250 TCP
10.250.0.50 10250 TCP
100.64.124.217 15032 TCP
100.64.0.1 443 TCP
10.250.0.108 10250 TCP
100.64.0.10 53 TCP
10.250.0.34 10250 TCP
10.250.0.8 10250 TCP
10.250.0.37 10250 TCP
100.64.124.217 15029 TCP
10.250.0.30 10250 TCP
10.250.0.36 10250 TCP
10.250.0.105 10250 TCP
100.64.124.217 15031 TCP
100.64.124.217 15030 TCP
10.250.0.92 10250 TCP
100.66.112.190 443 TCP
100.68.34.255 44134 TCP
100.64.124.217 15443 TCP
10.250.0.91 10250 TCP
10.250.0.97 10250 TCP
0.0.0.0 443 TCP
10.250.0.10 10250 TCP
10.250.0.45 10250 TCP
0.0.0.0 9943 TCP
100.64.132.219 9115 TCP
0.0.0.0 10249 TCP
100.70.99.95 443 TCP
100.65.54.197 26379 TCP
100.64.0.10 9153 TCP
0.0.0.0 9090 TCP
0.0.0.0 15014 TCP
100.71.44.89 6789 TCP
100.70.253.4 2020 TCP
0.0.0.0 9094 TCP
100.67.56.56 443 TCP
100.65.133.0 4314 TCP
0.0.0.0 4005 TCP
100.70.229.77 9411 TCP
0.0.0.0 9901 TCP
100.71.167.108 443 TCP
100.69.145.185 9093 TCP
100.70.32.142 443 TCP
100.66.233.175 42422 TCP
0.0.0.0 8080 TCP
100.69.114.203 6789 TCP
100.70.144.106 3300 TCP
0.0.0.0 20001 TCP
0.0.0.0 4004 TCP
0.0.0.0 9093 TCP
100.67.179.223 9000 TCP
100.70.18.125 3300 TCP
100.64.255.234 9090 TCP
100.66.197.157 9710 TCP
100.67.193.139 3300 TCP
100.69.114.203 3300 TCP
0.0.0.0 16909 TCP
0.0.0.0 3000 TCP
0.0.0.0 15004 TCP
100.68.54.218 9115 TCP
0.0.0.0 8060 TCP
0.0.0.0 8008 TCP
100.70.162.45 9115 TCP
0.0.0.0 15010 TCP
0.0.0.0 10054 TCP
100.65.13.208 5473 TCP
100.67.193.139 6789 TCP
100.71.44.89 3300 TCP
100.70.18.125 6789 TCP
100.67.56.56 8081 TCP
0.0.0.0 9411 TCP
0.0.0.0 2379 TCP
100.66.228.227 8081 TCP
0.0.0.0 9091 TCP
0.0.0.0 5556 TCP
100.64.124.217 15020 TCP
100.68.245.60 7000 TCP
0.0.0.0 9283 TCP
0.0.0.0 80 TCP
0.0.0.0 3100 TCP
100.66.228.227 8080 TCP
100.70.144.106 6789 TCP
0.0.0.0 1024 TCP
100.70.229.77 14268 TCP
0.0.0.0 15019 TCP
0.0.0.0 5558 TCP
100.70.229.77 14267 TCP
100.67.17.80 9100 TCP
0.0.0.0 15001 TCP
0.0.0.0 15006 TCP
100.96.1.142 443 TCP
0.0.0.0 15090 HTTP
为了能够在 istio 注入服务和外部服务(到 istio service-mesh)之间进行通信,您需要使用 ServiceEntry 对象。
根据 istio documentation:
ServiceEntry
enables adding additional entries into Istio’s internal service registry, so that auto-discovered services in the mesh can access/route to these manually specified services. A service entry describes the properties of a service (DNS name, VIPs, ports, protocols, endpoints). These services could be external to the mesh (e.g., web APIs) or mesh-internal services that are not part of the platform’s service registry (e.g., a set of VMs talking to services in Kubernetes). In addition, the endpoints of a service entry can also be dynamically selected by using the workloadSelector
field. These endpoints can be VM workloads declared using the WorkloadEntry
object or Kubernetes pods. The ability to select both pods and VMs under a single service allows for migration of services from VMs to Kubernetes without having to change the existing DNS names associated with the services.
就像你提到的:
pod1
在启用 Istio 的 namespace1 中运行
pod2
在禁用 Istio 的 namespace2 中运行并公开为 service2
在这种情况下,service2
将需要一个 ServiceEntry
对象,该对象会将其添加到 Istio 服务网格注册表中。这将允许 service2
像在 Istio 中一样使用。请注意,需要 envoy 代理的 istio 功能不适用于此服务,因为它实际上并未注入 istio。
我建议遵循这个 istio Accessing External Services 指南。
我有一种情况,我不确定我是否做错了什么,或者 Istio 是否完全不支持该用例。这是我的设置:
我有一个 VirtualService
连接到一个 Gateway
使一些 API 外部可用,例如作为 api1.example.com
。 VirtualService
连接到执行某些请求预处理(某些条件 URL 重写)的某些 Service
。现在是棘手的部分:服务应该将请求转发到某个 API 管理解决方案,该解决方案在同一集群上,在不同的命名空间中 运行,并且 没有 启用 Istio。这通常有效,但我有一些额外的要求困扰着我。 API 管理需要知道请求最初发送到哪个端点(以应用正确的规则),因此当我将请求从我的服务转发到 API 管理 pod 时,HTTP Host
header 应该仍然是 api1.example.com
。这是它中断的地方,我只收到 502 Bad Gateway
个错误。
现在这是完整的设置,但我认为您可以将其归结为以下设置(不幸的是,我目前无法访问我可以创建和测试一些最小工作示例的某些集群):
pod1
在namespace1
中运行并启用 Istiopod2
在禁用 Istio 的情况下在namespace2
中运行并公开为service2
现在来自pod1
以下作品:
wget -qO- http://service2.namespace2.svc.cluster.local
但以下不是:
wget -qO- --header 'Host: api1.example.com' http://service2.namespace2.svc.cluster.local
非常感谢任何帮助或提示!
针对提出的问题进行了一些更新:
- Istio 版本为 1.4.6
- 当我执行
wget -qO- http://service2.namespace2.svc.cluster.local
时pod2
收到请求,当我读取Host
header 时它是service2.namespace2.svc.cluster.local
- 当我执行
wget -qO- --header 'Host: api1.example.com' http://service2.namespace2.svc.cluster.local
时,请求根本不会到达pod2
istioctl proxy-config listeners pod1
显示如下(pod1中的服务是运行在1024端口,pod2中的是运行在80端口)
ADDRESS PORT TYPE
100.96.4.131 1024 HTTP
100.96.4.131 15020 TCP
100.69.164.43 443 TCP
10.250.0.42 10250 TCP
10.250.0.47 10250 TCP
100.64.124.217 443 TCP
100.67.245.255 15011 TCP
10.250.0.46 10250 TCP
10.250.0.48 10250 TCP
10.250.0.9 10250 TCP
10.250.0.24 10250 TCP
10.250.0.50 10250 TCP
100.64.124.217 15032 TCP
100.64.0.1 443 TCP
10.250.0.108 10250 TCP
100.64.0.10 53 TCP
10.250.0.34 10250 TCP
10.250.0.8 10250 TCP
10.250.0.37 10250 TCP
100.64.124.217 15029 TCP
10.250.0.30 10250 TCP
10.250.0.36 10250 TCP
10.250.0.105 10250 TCP
100.64.124.217 15031 TCP
100.64.124.217 15030 TCP
10.250.0.92 10250 TCP
100.66.112.190 443 TCP
100.68.34.255 44134 TCP
100.64.124.217 15443 TCP
10.250.0.91 10250 TCP
10.250.0.97 10250 TCP
0.0.0.0 443 TCP
10.250.0.10 10250 TCP
10.250.0.45 10250 TCP
0.0.0.0 9943 TCP
100.64.132.219 9115 TCP
0.0.0.0 10249 TCP
100.70.99.95 443 TCP
100.65.54.197 26379 TCP
100.64.0.10 9153 TCP
0.0.0.0 9090 TCP
0.0.0.0 15014 TCP
100.71.44.89 6789 TCP
100.70.253.4 2020 TCP
0.0.0.0 9094 TCP
100.67.56.56 443 TCP
100.65.133.0 4314 TCP
0.0.0.0 4005 TCP
100.70.229.77 9411 TCP
0.0.0.0 9901 TCP
100.71.167.108 443 TCP
100.69.145.185 9093 TCP
100.70.32.142 443 TCP
100.66.233.175 42422 TCP
0.0.0.0 8080 TCP
100.69.114.203 6789 TCP
100.70.144.106 3300 TCP
0.0.0.0 20001 TCP
0.0.0.0 4004 TCP
0.0.0.0 9093 TCP
100.67.179.223 9000 TCP
100.70.18.125 3300 TCP
100.64.255.234 9090 TCP
100.66.197.157 9710 TCP
100.67.193.139 3300 TCP
100.69.114.203 3300 TCP
0.0.0.0 16909 TCP
0.0.0.0 3000 TCP
0.0.0.0 15004 TCP
100.68.54.218 9115 TCP
0.0.0.0 8060 TCP
0.0.0.0 8008 TCP
100.70.162.45 9115 TCP
0.0.0.0 15010 TCP
0.0.0.0 10054 TCP
100.65.13.208 5473 TCP
100.67.193.139 6789 TCP
100.71.44.89 3300 TCP
100.70.18.125 6789 TCP
100.67.56.56 8081 TCP
0.0.0.0 9411 TCP
0.0.0.0 2379 TCP
100.66.228.227 8081 TCP
0.0.0.0 9091 TCP
0.0.0.0 5556 TCP
100.64.124.217 15020 TCP
100.68.245.60 7000 TCP
0.0.0.0 9283 TCP
0.0.0.0 80 TCP
0.0.0.0 3100 TCP
100.66.228.227 8080 TCP
100.70.144.106 6789 TCP
0.0.0.0 1024 TCP
100.70.229.77 14268 TCP
0.0.0.0 15019 TCP
0.0.0.0 5558 TCP
100.70.229.77 14267 TCP
100.67.17.80 9100 TCP
0.0.0.0 15001 TCP
0.0.0.0 15006 TCP
100.96.1.142 443 TCP
0.0.0.0 15090 HTTP
为了能够在 istio 注入服务和外部服务(到 istio service-mesh)之间进行通信,您需要使用 ServiceEntry 对象。
根据 istio documentation:
ServiceEntry
enables adding additional entries into Istio’s internal service registry, so that auto-discovered services in the mesh can access/route to these manually specified services. A service entry describes the properties of a service (DNS name, VIPs, ports, protocols, endpoints). These services could be external to the mesh (e.g., web APIs) or mesh-internal services that are not part of the platform’s service registry (e.g., a set of VMs talking to services in Kubernetes). In addition, the endpoints of a service entry can also be dynamically selected by using theworkloadSelector
field. These endpoints can be VM workloads declared using theWorkloadEntry
object or Kubernetes pods. The ability to select both pods and VMs under a single service allows for migration of services from VMs to Kubernetes without having to change the existing DNS names associated with the services.
就像你提到的:
pod1
在启用 Istio 的 namespace1 中运行
pod2
在禁用 Istio 的 namespace2 中运行并公开为 service2
在这种情况下,service2
将需要一个 ServiceEntry
对象,该对象会将其添加到 Istio 服务网格注册表中。这将允许 service2
像在 Istio 中一样使用。请注意,需要 envoy 代理的 istio 功能不适用于此服务,因为它实际上并未注入 istio。
我建议遵循这个 istio Accessing External Services 指南。