-
Notifications
You must be signed in to change notification settings - Fork 88
Description
Name and Version
redis 0.16.0
What is the problem this feature will solve?
when using the sentinel architecture, the redis client must be sentinel-aware. Otherwise, chances are that the plain redis client connects to one of the replicas, eventually resulting in write-attempts to a read-only replica.
As this client might be included in a piece of software we cannot modify ourselves, using a high availability architecture absurdly causes more outages then relying on the standalone architecture.
Describe the solution you'd like?
I imagine a proxy that can interact with sentinel to always be aware of the current master. A plain redis client then can connect to the proxy instance, effectively leveraging the high availability architecture without having to modify the code.
This could be achieved in these steps:
- have an initcontainer performing DNS lookups to discover all Redis Sentinel pods via the headless service, then iterate over those to establish a connection with the first responsive Sentinel instance using redis-cli
PINGcommands. - Once connected to a Sentinel, query it to auto-discover the master name using
SENTINEL masters. Retrieve the complete Redis topology including current master IP/port and replica information viaSENTINEL masterandSENTINEL replicascommands. - Generate a complete HAProxy configuration file with TCP health checks that authenticate with Redis, verify connectivity via PING, and crucially check
role:masterto ensure traffic only routes to the current master. Dynamically adds all StatefulSet pods (redis-0, redis-1, redis-2, ...) as backend servers. - HAProxy's built-in health checks continuously execute the
TCP check sequenceon all backend servers. Only the server responding withrole:masterpasses the health check, ensuring automatic failover when Sentinel promotes a new master during failures. - Alternatively, HAProxy provides an
agent-checkfeature. This could query sentinel in real-time to determine the current master.
What alternatives have you considered?
Buying new software that utilizes sentinel... But management did not like this idea.
Additional informations
I created a proof-of-concept that seems to work, but only tested on a local kubernetes cluster with little to none restrictions. I.E. installing "socat" is probably not a great idea. Nevertheless, maybe you get some inspiration.
Thanks for this awesome helm chart!
Affected Helm charts
redis