I'm building an application on GKE (Google Kubernetes Engine) and a system using GCE instances of Redis.
When I try to connect from the application pod on GKE to Redis on GCE, I get connection refused.(dial tcp <REMOTE-IP>:6379: connect: connection refused
)
The application is written in Go, and the redis library is go-redis(v8).
Why can't I connect?
The source code for the connection part and the part where the error occurs is as follows.
redisServerName = os.Getenv("REDIS_SERVER") // "sample.com:6379"
redisClient = redis.NewClient(&redis.Options{
Addr: redisServerName,
Password: "",
DB: 0,
})
p, err := redisClient.Ping(ctx).Result()
log.Println(p, err)
The hostname is resolved, so it is not a DNS problem, and the redis-cli commands are executable, so it does not seem to be a Firewall problem.
# redis-cli -h <REMOTE_IP> ping
PONG
- Postscript
Here is the result of running the command from the Pod with the Go application running
/# redis-cli -h redis.sample.com
redis.sample.com:6379> // can connect
/# nc redis.sample.com 6379
// There is NO response.