<p>I have a service &quot;A&quot; deployed in &quot;X&quot; namespace. &quot;Z&quot; service from &quot;P&quot; namespace, calls it on<br />
<code>svc-a.x.svc.cluster.local</code><br />
I have to deploy staging of service &quot;A&quot; in Y namespace as well and I want to register these IPs under<br />
<code>svc-a.x.svc.cluster.local</code><br />
Is there any way to do it? I want to the main service to select pods from different namespaces.</p>

xyphan
<p>You can try using a Service without selectors with an EndPointSlice which refers to a Service from each namespace.</p>
<p>Create <code>svc-a</code> in namespace <code>X</code> which selects / points to pods in namespace X.  The Service will be available at <code>svc-a.x.svc.cluster.local</code>.</p>
<p>Create <code>svc-a</code> in namespace <code>Y</code> which selects / points to pods in namespace Y. The Service will be available at <code>svc-a.y.svc.cluster.local</code>.</p>
<p>Create a <code>svc-a</code> in namespace <code>Z</code> without selectors.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: svc-a
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
</code></pre>
<p>The Service will be available at <code>svc-a.z.svc.cluster.local</code>.</p>
<p>Create an <a href="https://kubernetes.io/docs/concepts/services-networking/endpoint-slices/" rel="nofollow noreferrer">EndpointSlice</a> in namespace <code>Z</code> with <code>svc-a.x.svc.cluster.local</code> and <code>svc-a.y.svc.cluster.local</code> as endpoints and attach it to <code>svc-a</code>:</p>
<pre><code>apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
  name: svc-a
  labels:
    kubernetes.io/service-name: svc-a
addressType: FQDN
ports:
  - name: http
    protocol: TCP
    port: 80
endpoints:
  - addresses:
      - &quot;svc-a.x.svc.cluster.local&quot;
      - &quot;svc-a.y.svc.cluster.local&quot;
</code></pre>
<p>So now you'll have <code>svc-a.z.svc.cluster.local</code> available in any namespace pointing to backends in both the <code>X</code> and <code>Y</code> namespaces.</p>
