<p>A graph is always better than the last sentences, so here is what I would like to do :</p>
<p><a href="https://i.stack.imgur.com/A9eCa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A9eCa.png" alt="enter image description here" /></a></p>
<p>To sum up:</p>
<ul>
<li>I want to have a Redis master instance outside (or inside, this is not relevant here) my K8S cluster</li>
<li>I want to have a Redis slave instance <strong>per node</strong> replicating the master instance</li>
<li>I want that when removing a node, the Redis slave pod gets unregistered from master</li>
<li>I want that when adding a node, a Redis slave pod is added to the node and registered to the master</li>
<li>I want all pods in one node to consume only the data of the local Redis slave (easy part I think)</li>
</ul>
<p>Why do I want such an architecture?</p>
<ul>
<li>I want to take advantage of Redis master/slave replication to avoid dealing with cache invalidation myself</li>
<li>I want to have ultra-low latency calls to Redis cache, so having one slave per node is the best I can get (calling on local host network)</li>
</ul>
<p>Is it possible to automate such deployments, using Helm for instance? Are there domcumentation resources to make such an architecture with clean dynamic master/slave binding/unbinding?</p>
<p>And most of all, is this architecture a good idea for what I want to do? Is there any alternative that could be as fast?</p>

<p>i remember we had a discussion on this topic previously <a href="https://stackoverflow.com/questions/70257094/redis-master-slave-on-gcp-memorystore">here</a>, no worries adding more here.</p>
<p>Read more about the Redis helm chart : <a href="https://github.com/bitnami/charts/tree/master/bitnami/redis#choose-between-redis-helm-chart-and-redis-cluster-helm-chart" rel="nofollow noreferrer">https://github.com/bitnami/charts/tree/master/bitnami/redis#choose-between-redis-helm-chart-and-redis-cluster-helm-chart</a></p>
<blockquote>
<p>You should also be asking the question of how my application will be
connecting to POD on same Node without using the service of Redis.</p>
</blockquote>
<p>For that, you can use the `environment variables and expose them to <strong>application</strong> <strong>POD</strong>.</p>
<p>Something like :</p>
<pre><code>env:
- name: HOST_IP
  valueFrom:
    fieldRef:
      fieldPath: status.hostIP
</code></pre>
<p>It will give you the value of <strong>Node IP</strong> on which the <strong>POD</strong> is running, then you can use that IP to connect to <strong>DeamonSet</strong> (Redis slave if you are running).</p>
<p>You can read more at : <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/</a></p>
<blockquote>
<p>Is it possible to automate such deployments, using Helm for instance?</p>
</blockquote>
<p>Yes, you can write down your own Helm chart and deploy the generated <strong>YAML</strong> manifest.</p>
<blockquote>
<p>And most of all, is this architecture a good idea for what I want to
do? Is there any alternative that could be as fast?</p>
</blockquote>
<p>If you think then it is a good idea, as per my consideration this could create the <strong>$$$</strong> issue &amp; higher cluster resources usage.</p>
<p>What if you are running the 200 nodes on each you will be running the slave of Redis ? Which might consume resources on each node and add cost to your <strong>infra</strong>.</p>
<p><strong>OR</strong></p>
<p>if you are planning for <strong>specific deployment</strong></p>
<p>Your above suggestion is also good, but still, if you are planning to use the <strong>Redis</strong> with <strong>only Specific</strong> <strong>deployment</strong> you can use the sidecar pattern also and connect multiple Redis together using configuration.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    app: web
spec:
  ports:
  - port: 80
    name: redis
    targetPort: 5000
  selector:
    app: web
  type: LoadBalancer    
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: web
  replicas: 3
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: redis
        image: redis
        ports:
          - containerPort: 6379
            name: redis
            protocol: TCP        
      - name: web-app
        image: web-app
        env:       
          - name: &quot;REDIS_HOST&quot;
            value: &quot;localhost&quot;
</code></pre>
