<p>I have a container which exposes multiple ports. So, the kubernetes service configured for the deployment looks like the following:</p>

<pre><code>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
</code></pre>

<p>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?</p>

<p>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.</p>

<p>Is that possible with one virtualservice?</p>

enator
<p>Assuming that Istio <a href="https://istio.io/docs/reference/config/istio.networking.v1alpha3/#Gateway" rel="noreferrer">Gateway</a> is serving TCP network connections, you might be able to combine one <code>Gateway</code> configuration for two external ports 80 and 5556:</p>

<pre><code>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
</code></pre>

<p>Field <code>hosts</code> identifies here a list of target addresses that have to be exposed by this <code>Gateway</code>.</p>

<p>In order to make appropriate network routing to the nested Pods, you can specify <a href="https://istio.io/docs/reference/config/istio.networking.v1alpha3/#VirtualService" rel="noreferrer">VirtualService</a> with the matching set for the ports:</p>

<pre><code>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
</code></pre>

<p>Above <code>VirtualService</code> defines the rules to route network traffic coming on 80 and 8088 ports for <code>example.myhost.com</code> to the <code>myapp</code> service ports 5556, 5555 respectively.</p>

<p>I encourage you to get more information about Istio <a href="https://istio.io/docs/reference/config/istio.networking.v1alpha3/#TCPRoute" rel="noreferrer">TCPRoute</a> capabilities and further appliance.</p>
