1

I have a redis sentinel master slave setup with 1 master and 3 slaves and this is in Kubernetes environment.In the spring lettuce configuration, I have to specify the sentinels URLs with port numbers. How should I specify the URL for each sentinel? Spring doc specifies IP and port. In the local it's ok but when in k8s, how should I configure? I installed the set up with bitnami redis chart. Below is how it's done locally.

@Bean
public RedisConnectionFactory lettuceConnectionFactory() {
    RedisSentinelConfiguration sentinelConfig = 
        new RedisSentinelConfiguration().master("mymaster")
                                        .sentinel("127.0.0.1", 26379)
                                        .sentinel("127.0.0.1", 26380);
    return new LettuceConnectionFactory(sentinelConfig);
}

Thanks

deHaar
  • 17,687
  • 10
  • 38
  • 51
sachin
  • 1,220
  • 1
  • 14
  • 24

2 Answers2

1

First thing -> using the bitnami helm chart is the right way to do things.

Although a bit of a different implementation, heres how we implemented the same master slave setup AND also avoided the above problem while ensuring the MAXIMUM availability we ever witnessed (less than 2 secs Downtime for master)

  • We made two services - one for master and another for slaves.

  • a PV PVC that was shared between the slaves and master where ONLY Master would write and slaves would only read from PV

  • this way we could always ensure that there was 1 pod running ALL time for master and N replicas behind the headless service for slaves.

In application slaves and master URL's would always be different, thus ensuring a clear "WRITE" and "READ" isolation and improving the stability of system with almost no failures for reads.

user13424620
  • 134
  • 5
0

Install the helm chart with sentinel enabled

helm install my-release bitnami/redis --set sentinel.enabled=true

A service with name my-release-redis will be created and can be accessed via my-release-redis.namespacename.svc.cluster.local:26379 from any namespace and from the same namespace it's much simpler using my-release-redis:26379

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • I know that the service my-reelase-redis is created.But what should i provide in my sentinel()method as parameter.Should i repeat the service name and port for each sentinel pod or just one time? – sachin May 06 '20 at 11:20
  • You can use the service name once..behind the scenes it will connect to one of the pods – Arghya Sadhu May 06 '20 at 12:48
  • Thanks for the response.However when i install the chart there will be two services for redis . One is redis and other is redis-headless.My understanding is that i should use the headless-svc as the url parameter.Right? – sachin May 07 '20 at 05:27
  • So if you look at the helm installation output it says how to access sentinel and I think I saw redis there and not headless – Arghya Sadhu May 07 '20 at 05:32