<p>I have deployed an application on Kubernetes and exposed with Istio service mesh. There is 2 components in the application, UI and API. I am trying to setup canary based setup to enable AB testing. So, for these 2 components, there is 2 versions (v1 and v2) has deployed, so (min) 4 pods are running.</p>
<p>Assume, v1 is stable and v2 is release version. Version v1 will serve real internet traffic and version v2 will serve the request from specific ip address to make sure promotion of version v2 will not impact real production environment. Refer the attached image for clarity of traffic flow within application.</p>
<p><a href="https://i.stack.imgur.com/YXe14.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YXe14.png" alt="enter image description here" /></a></p>
<p>Testing of UI V2 (release version) is quite easy by filter real client ip address of user using virtualService-</p>
<pre><code>    - headers:
        x-forwarded-for:
          regex: .*1.2.3.4.*
</code></pre>
<p>Testing of API v2 (release version) is complex, because it is not exposed to internet and must serve traffic only from  UI v2 (release version) internally but I am unable to do.</p>
<pre><code>    url = &quot;http://service-api&quot;
    hdr = { 'CALLER_POD' : 'ui_v2_pod_hostname_with_release' }
    req = urllib.request.Request(url, headers=hdr)
    response = urllib.request.urlopen(req)
</code></pre>
<p>One hacky trick I have applied in application, added custom http request headers <strong>&quot;CALLER_POD&quot;</strong> while calling API from UI v2 pod, so that API virtualService can filter out request based on <strong>&quot;CALLER_POD&quot;</strong>. But it looks more complex because it need code refactoring on a broader level and more human manageable in future if any changes come.</p>
<p><strong>Is there any way to add UI v2 pod identity (preferable hostname) in http request header while calling API service internally on Kubernetes or Istio level.</strong></p>

<p>Have you tried using <code>sourceLabels</code> based <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPMatchRequest" rel="nofollow noreferrer">routing</a>? For example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: socks-com
spec:
  hosts:
  - sock.com
  http:
  - match:
    - sourceLabels:
        UI: v2
    - route:
      - destination:
          host: API
          label: v2
  - route:
    - destination:
        host: API
        subset: v1
</code></pre>
<p>It would also require <code>DestinationRule</code> update with two <code>subsets</code>.</p>
