<p>In my cluster I have a nodejs application pod and a redis pod, and I am trying to connect to redis from nodejs, but I am getting the following error:</p>

<p><code>[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)</code></p>

<p>It is worth noting that in my nodejs app I am pointing at redis:6379 and if I change the pointer to localhost:6379, I will get a <code>ECONNREFUSED</code> error.</p>

<p>My redis deployment yaml looks like this:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
    - name: redis
      image: redis:5.0.4
      command:
        - redis-server
        - '/redis-master/redis.conf'
      env:
        - name: MASTER
          value: 'true'
      ports:
        - containerPort: 6379
      resources:
        limits:
          cpu: '0.1'
      volumeMounts:
        - mountPath: /redis-master-data
          name: data
        - mountPath: /redis-master
          name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: redis-config
        items:
          - key: redis-config
            path: redis.conf

</code></pre>

<p>Mu redis service yaml is the following:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: redis-master
  labels:
    app: redis
    role: master
    tier: backend
spec:
  ports:
    - name: redis
      port: 6379
      targetPort: 6379
  selector:
    app: redis
    role: master
    tier: backend

</code></pre>

<p>And the service of my app looks like this:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: bff
  annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/port: '8080'
  labels:
    app: bff
spec:
  ports:
    - name: external
      port: 80
      targetPort: web
      protocol: TCP
    - name: metrics
      port: 8080
      targetPort: metrics
      protocol: TCP
  selector:
    app: bff

</code></pre>

<p>I have tried following other answers given to similar questions, but they do not seem to work in my case.</p>

Jacobdo
<p>The root cause is your service <code>selector</code> definition doesn't match your pods's lables.</p>

<p>Quote from Kubernetes service document:</p>

<blockquote>
  <p>The controller for the Service selector continuously scans for Pods that match its selector, and then POSTs any updates to an Endpoint object also named “my-service”.</p>
</blockquote>

<p>See <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">this link</a> for full document.</p>

<p>In short, by following <a href="https://github.com/kubernetes/examples/tree/master/guestbook" rel="nofollow noreferrer">this Kubernetes official example</a>, you should deploy the <code>deployment</code> "redis-master-deployment.yaml" instead of bare pod.</p>
