<p>I am trying to understand the VirtualService and DestinationRule resources in relation with the namespace which should be defined and if they are really namespaced resources or they can be considered as cluster-wide resources also.</p>
<p>I have the following scenario:</p>
<ul>
<li>The frontend service (web-frontend) access the backend service (customers).</li>
<li>The frontend service is deployed in the frontend namespace</li>
<li>The backend service (customers) is deployed in the backend namespace</li>
<li>There are 2 versions of the backend service customers (2 deployments), one related to the version v1 and one related to the version v2.</li>
<li>The default behavior for the clusterIP service is to load-balance the request between the 2 deployments (v1 and v2) and my goal is by creating a DestinationRule and a VirtualService to direct the traffic only to the deployment version v1.</li>
<li>What I want to understand is which is the appropriate namespace to define such DestinationRule and a VirtualService resources. Should I create the necessary DestinationRule and  VirtualService resources in the frontend namespace or in the backend namespace?</li>
</ul>
<p>In the frontend namespace I have the web-frontend deployment and and the related service as follow:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Namespace
metadata:
  name: frontend
  labels:
    istio-injection: enabled
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-frontend
  namespace: frontend
  labels:
    app: web-frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web-frontend
  template:
    metadata:
      labels:
        app: web-frontend
        version: v1
    spec:
      containers:
        - image: gcr.io/tetratelabs/web-frontend:1.0.0
          imagePullPolicy: Always
          name: web
          ports:
            - containerPort: 8080
          env:
            - name: CUSTOMER_SERVICE_URL
              value: 'http://customers.backend.svc.cluster.local'
---
kind: Service
apiVersion: v1
metadata:
  name: web-frontend
  namespace: frontend
  labels:
    app: web-frontend
spec:
  selector:
    app: web-frontend
  type: NodePort
  ports:
    - port: 80
      name: http
      targetPort: 8080

</code></pre>
<p>I have expose the web-frontend service by defining the following Gateway and VirtualService resources as follow:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: gateway-all-hosts
  # namespace: default # Also working
  namespace: frontend
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - &quot;*&quot;
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: web-frontend
  # namespace: default # Also working
  namespace: frontend
spec:
  hosts:
    - &quot;*&quot;
  gateways:
    - gateway-all-hosts
  http:
    - route:
        - destination:
            host: web-frontend.frontend.svc.cluster.local
            port:
              number: 80
</code></pre>
<p>In the backend namespace I have the customers v1 and v2 deployments and related service as follow:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Namespace
metadata:
  name: backend
  labels:
    istio-injection: enabled
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: customers-v1
  namespace: backend
  labels:
    app: customers
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: customers
      version: v1
  template:
    metadata:
      labels:
        app: customers
        version: v1
    spec:
      containers:
        - image: gcr.io/tetratelabs/customers:1.0.0
          imagePullPolicy: Always
          name: svc
          ports:
            - containerPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: customers-v2
  namespace: backend
  labels:
    app: customers
    version: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: customers
      version: v2
  template:
    metadata:
      labels:
        app: customers
        version: v2
    spec:
      containers:
        - image: gcr.io/tetratelabs/customers:2.0.0
          imagePullPolicy: Always
          name: svc
          ports:
            - containerPort: 3000
---
kind: Service
apiVersion: v1
metadata:
  name: customers
  namespace: backend
  labels:
    app: customers
spec:
  selector:
    app: customers
  type: NodePort
  ports:
    - port: 80
      name: http
      targetPort: 3000

</code></pre>
<p>I have created the following DestinationRule and  VirtualService resources to send the traffic only to the v1 deployment.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: customers
  #namespace: default # Not working
  #namespace: frontend # working
  namespace: backend # working
spec:
  host: customers.backend.svc.cluster.local
  subsets:
    - name: v1
      labels:
        version: v1
    - name: v2
      labels:
        version: v2
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: customers
  #namespace: default # Not working
  #namespace: frontend # working
  namespace: backend # working
spec:
  hosts:
    - &quot;customers.backend.svc.cluster.local&quot;
  http:
  ## route  - subset: v1
  - route:
      - destination:
          host: customers.backend.svc.cluster.local
          port:
            number: 80
          subset: v1
</code></pre>
<ul>
<li><p>The <strong>question</strong> is which is the appropriate namespace to define the VR and DR resources for the customer service?</p>
</li>
<li><p>From my test I see that I can use either the frontend namespace, or the backend namespace. Why the VR,DR can be created to the frontend namespace or in the backend namespaces and in both cases are working? Which is the correct one?</p>
</li>
<li><p>Are the DestinationRule and VirtualService resources really namespaced resources or can be considered as cluster-wide resources ?
Are the low level routing rules of the proxies propagated to all envoy proxies regardless of the namespace?</p>
</li>
</ul>

Gerassimos Mitropoulos
<p>A DestinationRule to actually be applied during a request needs to be on the destination rule lookup path:</p>
<pre><code>-&gt; client namespace
-&gt; service namespace
-&gt; the configured meshconfig.rootNamespace namespace (istio-system by default)
</code></pre>
<p>In your example, the &quot;web-frontend&quot; client is in the <strong>frontend</strong> Namespace (<code>web-frontend.frontend.svc.cluster.local</code>), the &quot;customers&quot; service is in the <strong>backend</strong> Namespace (<code>customers.backend.svc.cluster.local</code>), so the <code>customers</code> DestinationRule should be created in one of the following Namespaces: <strong>frontend</strong>, <strong>backend</strong> or <strong>istio-system</strong>. Additionally, please note that the <strong>istio-system</strong> Namespace isn't recommended unless the destination rule is really a global configuration that is applicable in all Namespaces.</p>
<p>To make sure that the destination rule will be applied we can use the <code>istioctl proxy-config cluster</code> command for the <code>web-frontend</code> Pod:</p>
<pre><code>$ istioctl proxy-config cluster web-frontend-69d6c79786-vkdv8 -n frontend | grep &quot;customers.backend.svc.cluster.local&quot;
SERVICE FQDN                                            PORT      SUBSET     DESTINATION RULE
customers.backend.svc.cluster.local                     80        -          customers.frontend
customers.backend.svc.cluster.local                     80        v1         customers.frontend
customers.backend.svc.cluster.local                     80        v2         customers.frontend
</code></pre>
<p>When the destination rule is created in the <strong>default</strong> Namespace, it will not be applied during the request:</p>
<pre><code>$ istioctl proxy-config cluster web-frontend-69d6c79786-vkdv8 -n frontend | grep &quot;customers.backend.svc.cluster.local&quot;
SERVICE FQDN                                            PORT      SUBSET    DESTINATION RULE
customers.backend.svc.cluster.local                     80        -        
</code></pre>
<p>For more information, see the <a href="https://istio.io/latest/docs/ops/best-practices/traffic-management/#cross-namespace-configuration" rel="nofollow noreferrer">Control configuration sharing in namespaces</a> documentation.</p>
