Something that I am not understanding about redis in K8s

6/28/2019

I setup redis in GKE using the helm chart.

It created 3 services redis-master, redis-slave, and redis-headless. When i connect to it over the "redis-headless" i get a error (about 66% of the time):

READONLY You can't write against a read only replica.

I assume this is because it is routing to two of the slave instances. If I use the master then it seems to work.

I assume that i should only use the redis-master to connect? Will it ever use the slave? Will it update if the master goes down? Should I ever route to slave (for read queries)?

I want to feel better on my understanding on how it is working (assuming it is).

Thank you

-- mornindew
google-kubernetes-engine
redis

1 Answer

6/30/2019

Assume you are referring to the stable/redis chart.

You can get more details by running: kubectl describe service <service_name>. Check the Selector and Endpoints fields. The redis-headless service selects all Redis pods, while redis-master only selects the Redis master pod, which is labeled role:master.

By default write operations can only be handled by a master, but you can read data from replicas. Redis replicas are mainly used for:

  1. Improving throughput. You can send read commands to replicas in case master is already busy with write operations. Note that by default replication happens asynchronously, therefore strong consistency is not guaranteed.

  2. High availability. By using Redis Sentinel, a replica can be promoted as the new master when the old master is considered unhealthy. This would also prevent a crashed master coming up with empty data when Redis persistence is not turned on.

For the stable/redis chart you can configure sentinel.enabled to enable Redis Sentinel and auto failover. There's also a stable/redis-ha chart.

-- sonicloong
Source: StackOverflow