0
votes

I deployed a k8s redis sentinel using the Helm chart: https://github.com/bitnami/charts/tree/master/bitnami/redis

I did change only these values ( https://github.com/bitnami/charts/blob/master/bitnami/redis/values.yaml ) :

auth:
  enabled: false
  sentinel: false
sentinel:
  enabled: true
  masterSet: mymaster

After the deployment, I got this message:

Redis™ can be accessed via port 6379 on the following DNS name from within your cluster:          
                                                                                                        
    redis.default.svc.cluster.local for read only operations                                            
                                                                                                        
For read/write operations, first access the Redis™ Sentinel cluster, which is available in port 26379 using the same domain name above.



To connect to your Redis™ server:

1. Run a Redis™ pod that you can use as a client:

   kubectl run --namespace default redis-client --restart='Never'  --image docker.io/bitnami/redis:6.2.6-debian-10-r103 --command -- sleep infinity

   Use the following command to attach to the pod:

   kubectl exec --tty -i redis-client \
   --namespace default -- bash

2. Connect using the Redis™ CLI:
   redis-cli -h redis -p 6379 # Read only operations
   redis-cli -h redis -p 26379 # Sentinel access

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace default svc/redis 6379:6379 &
    redis-cli -h 127.0.0.1 -p 6379

This is working nicely:

 kubectl get pods
NAME           READY   STATUS    RESTARTS   AGE
redis-node-0   2/2     Running   0          2m23s
redis-node-1   2/2     Running   0          71s
redis-node-2   2/2     Running   0          43s

But regarding access - to summarize - I have two options to access redis:

  1. read-only access at redis.default.svc.cluster.local:6379
  2. read-write access at redis.default.svc.cluster.local:26379 (some kind of sentinel access, what is that? I did not find docs about "sentinel access". Is this a master server?)

Now I want to connect my Flask caching module to it: https://flask-caching.readthedocs.io/en/latest/

As you can see, there is an option to connect to redis sentinel, however I have no idea how. This is the code I have:

from flask_caching import Cache
cache = Cache(app, config={
  'CACHE_TYPE': 'RedisSentinelCache', 
  'CACHE_REDIS_SENTINELS': ['redis.default.svc.cluster.local'], 
  'CACHE_REDIS_SENTINEL_MASTER': 'mymaster'}
)

My questions are:

  1. What should be in param CACHE_REDIS_SENTINELS? Should I somehow get IP addresses of each node and get those there?

  2. What should be in param CACHE_REDIS_SENTINEL_MASTER? Is it "mymaster" (sentinel -> masterSet?)

  3. Should I connect always to the read-write server (in this case, will other replicas be used)? Or do I need to adjust my app in this way: if I write I always use the sentinel access at port 26379, and in the case that I read I connect always to the read-only 6379 port? Do I need to maintain 2 connections?

Thank you