<p>I'm having issues when accessing a service present in another namespace.</p>
<p>I have 2 namespaces (in the same cluster) airflow-dev and dask-dev.</p>
<p><img src="https://i.stack.imgur.com/UrA7u.jpg" alt="enter image description here" /></p>
<p>In dask-dev namespace, I have dask cluster(dask scheduler and workers) deployed. Also, created a service (cluster IP) to dask-scheduler pod. I'm able to access dask-scheduler pod from chrome using 'kubectl port-forward' command.</p>
<p><code>kubectl port-forward --namespace dask-dev svc/dask-dev-scheduler 5002:80</code></p>
<p>However, am not able to access the service (or dask-scheduler pod) from a pod (airflow-scheduler) present in airflow-dev namespace. Getting '<strong>Host or service not found</strong>' error when trying to access it using the below</p>
<p><code>dask-dev-scheduler.dask-dev.svc.cluster.local:8786</code></p>
<p>Below is the service that I have created for dask-dev-scheduler. Could you please let me know how to access the service from airflow-dev namespace.</p>
<pre><code>apiVersion: v1
metadata:
  name: dask-dev-scheduler
  namespace: dask-dev
  labels:
    app: dask-dev
    app.kubernetes.io/managed-by: Helm
    chart: dask-dev-4.5.7
    component: scheduler
    heritage: Helm
    release: dask-dev
  annotations:
    meta.helm.sh/release-name: dask-dev
    meta.helm.sh/release-namespace: dask-dev
spec:
  ports:
    - name: dask-dev-scheduler
      protocol: TCP
      port: 8786
      targetPort: 8786
    - name: dask-dev-webui
      protocol: TCP
      port: 80
      targetPort: 8787
  selector:
    app: dask-dev
    component: scheduler
    release: dask-dev
  clusterIP: 10.0.249.111
  type: ClusterIP
  sessionAffinity: None
status:
  loadBalancer: {}

[1]: https://i.stack.imgur.com/UrA7u.jpg
</code></pre>

<p>You can use a local service to reference an external service (a service in a different namespace) using the service <a href="https://kubernetes.io/docs/concepts/services-networking/service/#externalname" rel="nofollow noreferrer">externalName Type</a>.</p>
<p><code>ExternalName</code> services do not have selectors, or any defined ports or endpoints, therefore, you can use an ExternalName service to direct traffic to an external service.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: service-b
  namespace: namespace-b
spec:
  selector:
    app: my-app-b
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: service-b-ref
  namespace: namespace-a
spec:
  type: ExternalName
  externalName: service-b.namespace-b.svc.cluster.local
</code></pre>
<p>Any traffic in <code>namespace-a</code> that connects to <code>service-b-ref:&lt;port&gt;</code> will be routed to <code>service-b</code> in <code>namespace-b</code> (<code>service-b.namespace-b.svc.cluster.local</code>)
Therefore, a call to <code>service-b-ref:3000</code> will route to our service-b.</p>
<hr />
<p>In your example, you'd just need to create a service in <code>airflow-dev</code> that will route traffic to the <code>dask-dev-scheduler</code> in the <code>dask-dev</code> namespace:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: dask-dev-svc
  namespace: airflow-dev
spec:
  type: ExternalName
  externalName: dask-dev-scheduler.dask-dev.svc.cluster.local
</code></pre>
<p>Therefore, all <code>airflow-dev</code> resources that need to connect to the <code>dask-dev-scheduler</code> would call: <code>dask-dev-svc:8786</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
metadata:
  name: dask-dev-scheduler
  namespace: dask-dev
spec:
  ports:
    - name: dask-dev-scheduler
      protocol: TCP
      port: 8786
      targetPort: 8786
# ...
  selector:
    app: dask-dev
</code></pre>
