当我尝试从Kubernetes内部连接到Redis时,总是连接失败

时间:2019-09-04 06:35:59

标签: node.js kubernetes redis ioredis

我在Kubernetes集群中部署了我的节点应用程序,当该应用程序尝试从Kubernetes外部连接到Redis时,它引发以下错误:

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

我试图在kubernetes集群中部署redis-cli,它可以访问redis服务。

1 个答案:

答案 0 :(得分:0)

您必须将Redis作为服务公开到集群中