<p>Today I am facing a problem that the redis in the kubernetes cluster shows error like this:</p>
<pre><code>2021-11-16T05:32:18 [INFO] - increment delete failed...,MobcError(RedisCMDError(An error was signalled by the server: You can't write against a read only replica.))
</code></pre>
<p>I check my redis config and found that the config url like this:</p>
<pre><code>redisConnectionStr=&quot;redis://default:password@cruise-redis-headless.reddwarf-cache.svc.cluster.local:6379/3&quot;
</code></pre>
<p>I check the servcie and found it mapped to the redis cluster master and replica, I was wonder the headness service user for what situation? why not only keep the master servcie and replica servcie? If read operate, use any of the servcie would be fine. If write, only use the master service. when should i use the headness service?</p>

Dolphin
<blockquote>
<p>why not only keep the master service and replica servcie?</p>
</blockquote>
<p>You can do it, if you could implement it. as redis helm maybe dont use specific labels to run Read/Write replicas so it's hard to divert and create the different services for <strong>read &amp; write</strong>.</p>
<p>If you are deploying the <strong>Redis</strong> using the helm it will create the two services into the <strong>K8s</strong> cluster</p>
<p>one is <strong>Headless</strong> service and another one normal <strong>service</strong> with the <strong>ClusterIP</strong>.</p>
<p>In the application side, we should be using the <strong>normal</strong> service.</p>
<p>So idea is that headless return the replicas IPs which will be used further by the application to manage the cluster if you are using the sentinel or Redis cluster.</p>
<p>If you are using the Normal service which will move or route the traffic automatically to <strong>Read/Write</strong> replicas based on the condition.</p>
<p>While if you are using the sentinel you can ping the sentinel service and it will return master and read replicas IP.</p>
<p>Inside code you can use as per requirement now as you are getting both write and read ip with sentinel.</p>
<p>Inside the <strong>helm</strong> chart you can see one configuration</p>
<pre><code>sentinel:
  enabled: true
</code></pre>
<p>In the bitnami <a href="https://github.com/bitnami/charts/tree/master/bitnami/redis#master-slave-with-sentinel" rel="noreferrer">docs</a> they explicitly mention This command will return the address of the current master, which can be accessed from inside the cluster..</p>
<p>Read more at : <a href="https://github.com/bitnami/charts/tree/master/bitnami/redis#master-replicas-with-sentinel" rel="noreferrer">https://github.com/bitnami/charts/tree/master/bitnami/redis#master-replicas-with-sentinel</a></p>
