<p>I am deploying a NodeJS server with 3 replicas and connect to <strong>Redis</strong> to use Sub/Pub function.</p>
<p><strong>NodeJS:</strong></p>
<pre><code>const redis = require('redis');
const REDISPORT = 6379;
const subscriber = redis.createClient(REDISPORT, 'redis-service.default.svc.cluster.local');
const publisher = redis.createClient(REDISPORT, 'redis-service.default.svc.cluster.local');
</code></pre>
<p><strong>Error</strong> in all three NodeJS pods:</p>
<pre><code>Error: Redis connection to redis-service.default.svc.cluster.local:6379 failed - connect ECONNREFUSED 10.120.14.77:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Emitted 'error' event on RedisClient instance at:
    at RedisClient.on_error (/usr/src/app/node_modules/redis/index.js:341:14)
    at Socket.&lt;anonymous&gt; (/usr/src/app/node_modules/redis/index.js:222:14)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '10.120.14.77',
  port: 6379
}
</code></pre>
<p>You can see when I use <strong>'redis-service.default.svc.cluster.local'</strong> in NodeJS pod, it will get my Redis service ip <strong>10.120.14.77:6379</strong> automatically.</p>
<p>And my <strong>Redis</strong> service ip is the same as <strong>10.120.14.77:6379</strong> when I check with &quot;kubectl get svc redis&quot;</p>
<pre><code>- kubectl get svc redis
redis-service   ClusterIP   10.120.14.77   &lt;none&gt;        6379/TCP   74s

- kubectl logs redis
27 Sep 2020 08:41:20.309 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
</code></pre>
<p><strong>server-deployment.yml:</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: car-server-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: car-server
    spec:
      containers:
        - name: car-server
          image: gcr.io/PROJECT_ID/IMAGE_SERVER:TAG
          ports:
            - containerPort: 8080
              name: nodejs-port
  selector:
    matchLabels:
      app: car-server
</code></pre>
<p><strong>server-service.yml:</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: car-server-service
spec:
  ports:
    - port: 8080
      protocol: TCP
  selector:
    app: car-server
  type: NodePort
</code></pre>
<p><strong>redis-pod.yml:</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: redis
  labels:
    app: redis
spec:
  containers:
  - name: redis
    image: redis:5.0.4
    command:
      - redis-server
    env:
    - name: MASTER
      value: &quot;true&quot;
    ports:
    - containerPort: 6379
</code></pre>
<p><strong>redis-service.yml:</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: redis-service
spec:
  ports:
    - port: 6379
      protocol: TCP
  selector:
    app: redis
  type: ClusterIP
</code></pre>

potato
<p>Attempting for several hours and finally fix it. It is a small mistake when I create <strong>kustomization.yml</strong>. Therefore, basically not relevant to Redis or NodeJS.</p>
<p>Previous wrong file: <strong>kustomization.yml:</strong></p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
  app: my-app
bases:
- ./yaml
</code></pre>
<p>I put the commonLabels here and kustomize covered my Redis label and led to network error.</p>
<p>This is because I also used &quot;<strong>app label</strong>&quot; in my redis pod.</p>
<p>New file: <strong>kustomization.yml:</strong></p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ./yaml
</code></pre>
