大网数据广告活动
服务器运维问答

How to configure Redis Cluster inside a Kubernetes cluster to be accessible by external applications

· 52CE 我爱测

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, whenev…

问题原文

原帖链接 · 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.

  1. Setup the Redis cluster in K8's
  2. Deploy the redis-cluster-proxy and set it up to connect to your redis cluster
  3. Create a K8's external service to point to the redis-cluster-proxy instance, NOT the actual redis cluster instance
  4. 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-09-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。