<p>Could I create an traffic strategy in order to route traffic between services running in different kubernetes' namespaces?</p>

<p>Currently, my testing service is located at <code>staging</code> namespace. By other hand, my service in production are on <code>production</code> namespace.</p>

<p>I'd like to balance traffic between service located in <code>staging</code> namespace and <code>production</code> namespace. So, 10% goes to <code>staging:service</code> and 90% goes to <code>production:service</code>.</p>

<p>Up to now, I've been able to create a virtual service and a destination rule, but both services running inside the same namespace.</p>

<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  creationTimestamp: null
  name: recommendation
  namespace: istio-project
spec:
  host: recommendation
  subsets:
  - labels:
      version: v1
    name: version-v1
  - labels:
      version: v2
    name: version-v2
</code></pre>

<p>And a <code>VirtualService</code>:</p>

<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  creationTimestamp: null
  name: recommendation
  namespace: istio-project
spec:
  hosts:
  - recommendation
  http:
  - route:
    - destination:
        host: recommendation
        subset: version-v1
      weight: 75
    - destination:
        host: recommendation
        subset: version-v2
      weight: 25
</code></pre>

<p>This configuration is balancin between both services running inside <code>istio-project</code> namespace.</p>

<p>Any ideas?</p>

<p><strong>EDIT</strong></p>

<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  creationTimestamp: null
  name: recommendation
  namespace: istio-project
spec:
  hosts:
  - recommendation
  http:
  - route:
    - destination:
        host: recommendation
      weight: 75
    - destination:
        host: recommendation.istio-project-two.svc.cluster.local
      weight: 25
---
</code></pre>

Jordi
<blockquote>
  <p>Any ideas?</p>
</blockquote>

<p>Did you try with FQDN to cover for cross-namespace pods. It is in format <code>servicename.namespace.svc.cluster.local</code>. In the <a href="https://istio.io/docs/reference/config/istio.networking.v1alpha3/" rel="nofollow noreferrer">istio documentation</a> for VirtualServices this is referenced in their example as:</p>

<pre><code>spec:
  hosts:
  - ratings.prod.svc.cluster.local
</code></pre>

<p>where <code>ratings</code> would be service name, <code>prod</code> would be namespace in that particular example. Also they list:</p>

<pre><code>...
  namespace: foo
spec:
  host: reviews # interpreted as reviews.foo.svc.cluster.local
...
</code></pre>

<p>with cross namespace example:</p>

<pre><code>...
spec:
  hosts:
  - productpage.prod.svc.cluster.local # ignores rule namespace
...
</code></pre>

<p>In the <a href="https://istio.io/docs/reference/config/istio.networking.v1alpha3/#VirtualService" rel="nofollow noreferrer">other part of documentation</a> they specifically suggest usage of FQDN for Kubernetes users, quote:</p>

<blockquote>
  <blockquote>
    <p>Note for Kubernetes users: When short names are used (e.g. “reviews” instead of “reviews.default.svc.cluster.local”), Istio will interpret the short name based on the namespace of the rule, not the service. A rule in the “default” namespace containing a host “reviews will be interpreted as “reviews.default.svc.cluster.local”, irrespective of the actual namespace associated with the reviews service. To avoid potential misconfigurations, it is recommended to always use fully qualified domain names over short names.</p>
  </blockquote>
</blockquote>

<p>If I understand your configuration correctly you would need: <code>recommendation.staging.svc.cluster.local</code> and <code>recommendation.production.svc.cluster.local</code> respectively as hosts to route across namespaces.</p>

<h3>Edit for comment:</h3>

<p>If you would like to route <code>recommendation.istio-project.svc.cluster.local</code> to pods running in that and <code>recommendation.istio-project-two.svc.cluster.local</code> services in said percentages then yes, this looks like valid config.</p>
