如何为公开多个端口的服务配置Istio的虚拟服务? [英] How to configure Istio's virtualservice for a service which exposes multiple ports?

查看:185
本文介绍了如何为公开多个端口的服务配置Istio的虚拟服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个暴露多个端口的容器.因此,为部署配置的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.

为了对嵌套Pod进行适当的网络路由,您可以指定

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆