问题原文
原帖链接 · shrumm · CC BY-SA 4.0
I'm having trouble exposing my Redis Cluster on Kubernetes to external applications. Using a Kubernetes load balancer service, I'm able to assign an external IP to Redis which provides initial connectivity. The trouble is, whenever the client receives a MOVED command, the IP address is a Kubernetes internal POD IP which is inaccessible by redis clients outside the cluster.
Here's an example session from redis-cli to demonstrate:
10.150.0.5:7000> set test value
-> Redirected to slot [6918] located at 10.28.1.9:6379
Could not connect to Redis at 10.28.1.9:6379: Operation timed out
How do you solve this? None of the tutorials / guides I've read shed much light on exposing the cluster to external services. Most are concerned with getting the Redis cluster setup in K8s.
已采纳解答
原帖链接 · shrumm · CC BY-SA 4.0
For anyone still searching for an answer, the best option I've found is to use the (now official) Redis Proxy https://github.com/RedisLabs/redis-cluster-proxy.
Note: As Yogesh mentions in his comment - this is alpha code - so please avoid doing this in production workloads till the code is stable / you know what you're doing.
- Setup the Redis cluster in K8's
- Deploy the redis-cluster-proxy and set it up to connect to your redis cluster
- Create a K8's external service to point to the redis-cluster-proxy instance, NOT the actual redis cluster instance
- Your apps should use this service to connect to Redis
Explanation The proxy basically 'pretends' to be a single Redis instance, so clients connecting to it don't need to be cluster aware.
You should use a recent version of Redis, preferably v6 or higher.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
