<p>I'm trying to set up balancing between applications in different namespaces with Istio. But I am always getting reply from one application in dev namespace. My point is get response from applications from same prefix, like: <a href="http://example.com" rel="nofollow noreferrer">http://example.com</a> - need to balance between namespaces <code>dev</code>, <code>staging</code>, <code>production</code></p>
<p>I deployed <code>VirtualService</code>, <code>DestinationRule</code> and <code>Gateway</code> in different namespaces. Also I have tried to deploy one <code>Gateway</code> in the <code>istio-system</code> namespace and set correct path to it in the all of <code>VirtualService</code>.
Obviously I don't understand how it works...
My <code>VirtualService</code></p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: istio-nginx-vs
  namespace: dev
spec:
  hosts:
  - xxx.elb.amazonaws.com
  gateways:
  - dev/istio-nginx-gw
  http:
  - route:
    - destination:
        host: istio-nginx.dev.svc.cluster.local
        port:
          number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: istio-nginx-vs
  namespace: staging
spec:
  hosts:
  - xxx.elb.amazonaws.com
  gateways:
  - staging/istio-nginx-gw
  http:
  - route:
    - destination:
        host: istio-nginx.staging.svc.cluster.local
        port:
          number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: istio-nginx-vs
  namespace: production
spec:
  hosts:
  - xxx.elb.amazonaws.com
  gateways:
  - production/istio-nginx-gw
  http:
  - route:
    - destination:
        host: istio-nginx.production.svc.cluster.local
        port:
          number: 80
</code></pre>
<p>Here is the <code>DestinationRule</code></p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: istio-nginx-dr
  namespace: dev
spec:
  host: istio-nginx.svc.dev.cluster.local
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: istio-nginx-dr
  namespace: staging
spec:
  host: istio-nginx.staging.svc.cluster.local
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: istio-nginx-dr
  namespace: production
spec:
  host: istio-nginx.production.svc.cluster.local
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
</code></pre>
<p>And the <code>Gateway</code></p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-nginx-gw
  namespace: dev
spec:
  selector:
    app: istio-gateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - xxx.elb.amazonaws.com
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-nginx-gw
  namespace: staging
spec:
  selector:
    app: istio-gateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - xxx.elb.amazonaws.com
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-nginx-gw
  namespace: production
spec:
  selector:
    app: istio-gateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - xxx.amazonaws.com
</code></pre>

Валерий Сиволапенко
<p>As the hosts &quot;xxx.elb.amazonaws.com&quot; value in different gateway definitions of different namespace is same for the &quot;istio-nginx&quot; service.  So only one routing rule would have got applied.  So the requests would be serviced from single application.  For more details on routing rule precedence can be referred in <a href="https://istio.io/latest/docs/concepts/traffic-management/#routing-rule-precedence" rel="nofollow noreferrer">istio documentation</a></p>
<p>Using 'istioctl&quot; tool you can verify the routes configured.</p>
<pre><code>istioctl pc routes deploy/istio-ingressgateway.istio-system | grep &quot;istio-nginx&quot;
</code></pre>
