skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search