When I try to connect to Redis from inside Kubernetes, always got connection failed

9/4/2019

I have my node app deployed inside Kubernetes cluster, when the app tries to connect to Redis outside from the Kubernetes, it throws following error:

2019-09-04T06:21:55.320Z ioredis:redis status[101.37.199.xx:6379]: connecting -> connect
2019-09-04T06:21:55.321Z ioredis:redis write command[101.37.199.xx:6379]: 32 -> auth([ 'xxxxxx' ])
2019-09-04T06:21:55.321Z ioredis:redis write command[101.37.199.xx:6379]: 32 -> select([ '32' ])
2019-09-04T06:21:55.321Z ioredis:connection error: Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:146:25)
    at writeGeneric (internal/stream_base_commons.js:137:3)
    at Socket._writeGeneric (net.js:698:11)
    at Socket._write (net.js:710:8)
    at doWrite (_stream_writable.js:417:12)
    at writeOrBuffer (_stream_writable.js:401:5)
    at Socket.Writable.write (_stream_writable.js:301:11)
    at Redis.sendCommand (/app/node_modules/ioredis/built/redis/index.js:601:33)
    at Redis.select (/app/node_modules/ioredis/built/commander.js:124:21)
    at Socket.<anonymous> (/app/node_modules/ioredis/built/redis/event_handler.js:32:18) {
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write'
}
[ioredis] Unhandled error event: Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:146:25)
    at writeGeneric (internal/stream_base_commons.js:137:3)
    at Socket._writeGeneric (net.js:698:11)
    at Socket._write (net.js:710:8)
    at doWrite (_stream_writable.js:417:12)
    at writeOrBuffer (_stream_writable.js:401:5)
    at Socket.Writable.write (_stream_writable.js:301:11)
    at Redis.sendCommand (/app/node_modules/ioredis/built/redis/index.js:601:33)
    at Redis.select (/app/node_modules/ioredis/built/commander.js:124:21)
    at Socket.<anonymous> enter code here(/app/node_modules/ioredis/built/redis/event_handler.js:32:18)
2019-09-04T06:21:55.324Z ioredis:redis queue command[101.37.199.xx:6379]: 32 -> info([])
2019-09-04T06:21:55.324Z ioredis:redis status[101.37.199.xx:6379]: connect -> close

I've tried to deploy redis-cli inside the kubernetes cluster, it can access the redis service.

-- shawn liu
ioredis
kubernetes
node.js
redis

1 Answer

9/4/2019

you have to expose redis as a service in your cluster

-- prisar
Source: StackOverflow