如何为公开多个端口的服务配置Istio的虚拟服务? [英] How to configure Istio's virtualservice for a service which exposes multiple ports?
问题描述
我有一个暴露多个端口的容器.因此,为部署配置的kubernetes服务如下所示:
I have a container which exposes multiple ports. So, the kubernetes service configured for the deployment looks like the following:
kind: Service
apiVersion: v1
metadata:
name: myapp
labels:
app: myapp
spec:
selector:
name: myapp
ports:
- protocol: TCP
port: 5555
targetPort: 5555
- protocol: TCP
port: 5556
targetPort: 5556
我使用Istio来管理路由并通过istio入口网关公开此服务. 我们有一个用于80端口的网关,我们是否必须为具有两个不同虚拟服务的同一主机创建两个不同的网关?
I use Istio to manage routing and to expose this service via istio ingress gateway. We have one gateway for port 80, do we have to create two different gateways for the same host with two different virtual service?
我想配置"example.myhost.com"的80路由到5556和其他端口,比如说"example.myhost.com"的8088路由到服务5555.
I want to configure that "example.myhost.com" 's 80 route to 5556 and some other port, let say, "example.myhost.com" 's 8088 route to 5555 of the service.
使用一种虚拟服务可能吗?
Is that possible with one virtualservice?
推荐答案
假设Istio 网关正在为TCP网络连接提供服务,您可以为两个外部端口80和5556组合一个Gateway
配置:
Assuming that Istio Gateway is serving TCP network connections, you might be able to combine one Gateway
configuration for two external ports 80 and 5556:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: myapp-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: port1
protocol: TCP
hosts:
- example.myhost.com
- port:
number: 8088
name: port2
protocol: TCP
hosts:
- example.myhost.com
字段hosts
在此标识此Gateway
必须公开的目标地址的列表.
Field hosts
identifies here a list of target addresses that have to be exposed by this Gateway
.
In order to make appropriate network routing to the nested Pods, you can specify VirtualService with the matching set for the ports:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: myapp-virtual-service
spec:
hosts:
- example.myhost.com
gateways:
- myapp-gateway
tcp:
- match:
- port: 80
route:
- destination:
host: myapp.prod.svc.cluster.local
port:
number: 5556
- match:
- port: 8088
route:
- destination:
host: myapp.prod.svc.cluster.local
port:
number: 5555
VirtualService
上方的规则定义了将来自example.myhost.com
的80和8088端口的网络流量分别路由到myapp
服务端口5556、5555的规则.
Above VirtualService
defines the rules to route network traffic coming on 80 and 8088 ports for example.myhost.com
to the myapp
service ports 5556, 5555 respectively.
我鼓励您获取有关Istio的更多信息 TCPRoute 功能和其他设备.
I encourage you to get more information about Istio TCPRoute capabilities and further appliance.
这篇关于如何为公开多个端口的服务配置Istio的虚拟服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!