title: How to connect Redis with service in NodeJS in K8s cluster?
body: <p>I am developing an application (car-app) which uses socket.io. and now I am going to deploy it to kubernetes cluster. Then I use Redis pub/sub function to communicate.</p>
  <pre><code>My app structure:
    Backend: NodeJS
    Frontend: ReactJS
    Mongodb
  </code></pre>
  <p>Then I am trying to connect Redis in NodeJS. It can be run on my localhost, but it cannot run on my GKE cluster.</p>
  <pre><code>(NodeJS)
  const redis = require('redis');
  const REDISPORT = 6379;
  const subscriber = redis.createClient(REDISPORT, redis);
  </code></pre>
  <p>Error while running on GKE cluster:</p>
  <blockquote>
  <p>Error: Redis connection to 127.0.0.1:6379 failed - connect
  ECONNREFUSED 127.0.0.1:6379</p>
  </blockquote>
  <p>I think this maybe caused by service connection and my redis deployment and service are configured below.</p>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: car-redis-deployment
  spec:
    replicas: 3
    template:
      metadata:
        labels:
          app: car-redis
      spec:
        containers:
          - name: car-redis
            image: redis:latest
            ports:
              - containerPort: 6379
                name: http-port
    selector:
      matchLabels:
        app: car-redis
  </code></pre>
  <hr />
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: car-redis-service
  spec:
    ports:
      - port: 6379
        protocol: TCP
        targetPort: 6379
    selector:
      app: car-redis
    type: NodePort
  </code></pre>