<p>I am following this image architecture from K8s</p>
<p><a href="https://i.stack.imgur.com/2gu6N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2gu6N.png" alt="enter image description here" /></a></p>
<p>However I can not seem to connect to socket.io server <strong>from within</strong> the cluster using the service name</p>
<p>Current situation:</p>
<p>From POD B</p>
<ul>
<li>Can connect directly to App A's pod using WS ( ws://10.10.10.1:3000 ) ✅</li>
<li>Can connect to App A's service using HTTP ( http://orders:8000 ) ✅</li>
<li><strong>Can not connect to App A's service using WS ( ws://orders:8000 )</strong> ❌</li>
</ul>
<p>From outside world / Internet</p>
<ul>
<li><p><strong>Can connect to App A's service using WS ( ws://my-external-ip/orders )</strong>  ✅ // using traefik to route my-external-ip/orders to service orders:8000</p>
</li>
<li><p>Can connect to App A's service using HTTP ( http://my-external-ip/orders )  ✅ // using traefik to route my-external-ip/orders to service orders:8000</p>
</li>
</ul>
<p>My current service configuration</p>
<pre><code>spec:
  ports:
    - name: http
      protocol: TCP
      port: 8000
      targetPort: 3000
  selector:
    app: orders
  clusterIP: 172.20.115.234
  type: ClusterIP
  sessionAffinity: None
</code></pre>
<p>My Ingress Helm chart</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template &quot;app.name&quot; $ }}-backend
  annotations:
    kubernetes.io/ingress.class: traefik
    ingress.kubernetes.io/auth-type: forward
    ingress.kubernetes.io/auth-url: &quot;http://auth.default.svc.cluster.local:8000/api/v1/oauth2/auth&quot;
    ingress.kubernetes.io/auth-response-headers: authorization
  labels:
    {{- include &quot;api-gw.labels&quot; $ | indent 4 }}
spec:
  rules:
    - host: {{ .Values.deploy.host | quote }}
      http:
        paths:
          - path: /socket/events
            backend:
              serviceName: orders
              servicePort: 8000
</code></pre>
<p>My Service Helm chart</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: {{ template &quot;app.name&quot; . }}
spec:
  {{ if not $isDebug -}}
  selector:
    app: {{ template &quot;app.name&quot; . }}
  {{ end -}}
  type: NodePort
  ports:
  - name: http
    port: {{ template &quot;app.svc.port&quot; . }}
    targetPort: {{ template &quot;app.port&quot; . }}
    nodePort: {{ .Values.service.exposedPort }}
    protocol: TCP



# Helpers..
# {{/* vim: set filetype=mustache: */}}
# {{- define &quot;app.name&quot; -}}
#     {{ default &quot;default&quot; .Chart.Name }}
# {{- end -}}

# {{- define &quot;app.port&quot; -}}
# 3000
# {{- end -}}

# {{- define &quot;app.svc.port&quot; -}}
# 8000
# {{- end -}}
</code></pre>

<p>The services DNS name must be set in your container to access its VIP address.
Kubernetes automatically sets environmental variables in all pods which have the <strong>same selector</strong> as the <strong>service</strong>.</p>
<p>In your case, all pods with <strong>selector A</strong>, have environmental variables set in them when the container is deploying, that contain the services VIP and PORT.</p>
<p>The other pod with <strong>selector B</strong>, is not linked as an endpoints for the service, therefor, it does not contain the environmental variables needed to access the service.</p>
<p>Here is the  <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#accessing-the-service" rel="nofollow noreferrer">k8s documentation</a> related to your problem.</p>
<p>To solve this, you can setup a DNS service, which k8s offers as a cluster addon.
Just follow the documentation.</p>
