Skip to content

Redis: Add sentinel-aware proxy #670

@ghmer

Description

@ghmer

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:

  1. 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 PING commands.
  2. 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 via SENTINEL master and SENTINEL replicas commands.
  3. Generate a complete HAProxy configuration file with TCP health checks that authenticate with Redis, verify connectivity via PING, and crucially check role:master to ensure traffic only routes to the current master. Dynamically adds all StatefulSet pods (redis-0, redis-1, redis-2, ...) as backend servers.
  4. HAProxy's built-in health checks continuously execute the TCP check sequence on all backend servers. Only the server responding with role:master passes the health check, ensuring automatic failover when Sentinel promotes a new master during failures.
  5. Alternatively, HAProxy provides an agent-check feature. 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!

redis-proxy-configmap.yaml

redis-proxy-deployment.yaml

Affected Helm charts

redis

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestredisIssues regarding the redis chart

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions