How to use Sentinel on Kubernetes?

432 views
Skip to first unread message

Bart van deenen

unread,
Aug 4, 2020, 3:54:04 AM8/4/20
to lettuce-redis-client-users
Hi all

I can't get my Redis client configured correctly using the bitnami Redis helm chart. I've configured the helm chart to use the sentinel (`cluster.enabled=true`, `sentinel.enabled=true`).

The bitnami chart exposes two services:

kubectl get svc,endpoints -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/redis ClusterIP 10.20.5.73 6379/TCP,26379/TCP 2m42s app=redis,release=redis service/redis-headless ClusterIP None 6379/TCP,26379/TCP 2m42s app=redis,release=redis service/redis-metrics ClusterIP 10.20.4.149 9121/TCP 2m42s app=redis,release=redis NAME ENDPOINTS AGE endpoints/redis 10.16.1.46:26379,10.16.2.88:26379,10.16.4.76:26379 + 5 more... 2m42s endpoints/redis-headless 10.16.1.46:26379,10.16.2.88:26379,10.16.4.76:26379 + 5 more... 2m42s endpoints/redis-metrics 10.16.1.46:9121,10.16.2.88:9121,10.16.4.76:9121 + 1 more... 2m42s

I'm trying to define a client that I can use to write data, and one that can be used read-only for the slave nodes.

This one for instance gives me read-only errors when I try to set values.

RedisURI redisUri = RedisURI.Builder
                .sentinel("redis")
                .redis("redis")
                .withPassword(redisPassword)
                .build();
RedisClient redisClient = RedisClient.create(redisUri);
RedisCommands<String, String> commands = redisClient.connect().sync();

So what would be the correct initializations for a read-only RedisCommands instance, and for a read-write?

Thanks

Mark Paluch

unread,
Aug 4, 2020, 4:53:20 AM8/4/20
to lettuce-redis-client-users
Hi Bart, 

Thanks for reaching out. The short answer is: Exactly the same as if you would have access to sentinel hostnames/ports, the master Id and password.

Since this is the Lettuce community, we don't really have insight into all the various ways to orchestrate Redis runtimes. The list of endpoints (10.16.1.46:26379,10.16.2.88:26379,10.16.4.76:26379) looks already like the thing you need as list of Sentinels. The only thing that is missing is the masterId.


RedisURI redisUri = RedisURI.Builder.sentinel("sentinelhost1", "mymaster").withSentinel("sentinelhost2").build();
RedisClient client = RedisClient.create(redisUri);

RedisConnection<String, String> connection = client.connect();

Cheers, 
Mark

Bart van deenen

unread,
Aug 4, 2020, 5:22:01 AM8/4/20
to lettuce-redis-client-users
Hi Mark

Is the RedisConnection that your code returns for read-write (to the master) or read-only (to one of the slaves) ?

Thanks

Bart

Mark Paluch

unread,
Aug 5, 2020, 7:38:44 AM8/5/20
to lettuce-redis-client-users
That is a connection that connects to the active master node including failover.
Reply all
Reply to author
Forward
0 new messages