Redis Cluster Client doesn't work with Redis cluster on GKE

7/23/2019

My setup has a K8S Redis cluster with 8 nodes and 32 pods across them and a load balancer service on top.

I am using a Redis cluster client to access this cluster using the load balancer's external IP. However, when handling queries, as part of Redis cluster redirection (MOVED / ASK), the cluster client receives internal IP addresses of the 32 Pods, connection to which fails within the client.

For example, I provide the IP address of the load balancer (35.245.51.198:6379) but the Redis cluster client throws errors like - Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host 10.32.7.2:6379, which is an internal Pod IP.

Any ideas about how to deal with this situation will be much appreciated.

Thanks in advance.

-- user1474341
kubernetes
redis
redis-cluster

1 Answer

7/24/2019

If you're running on GKE, you can NAT the Pod IP using the IP masquerade agent:

Using IP masquerading in your clusters can increase their security by preventing individual Pod IP addresses from being exposed to traffic outside link-local range (169.254.0.0/16) and additional arbitrary IP ranges

Your issue specifically is that, the pod range is on 10.0.0.0/8, which is by default a non-masquerade CIDR.

You can change this using a ConfigMap to treat that range as masquerade so that it picks the node's external IP as source address.

Alternatively, you can change the pod range in your cluster to anything that is masked.

-- yyyyahir
Source: StackOverflow