Redis - Cluster Setup

Created by Shafeen Panjwani, Modified on Thu, 20 Jul, 2023 at 12:19 PM by Shafeen Panjwani

Prerequisites

Environment Variables

  • REDIS_CLUSTER

Comma separated host and port details. Eg: 127.0.0.1,127.0.0.2:8990 results in 127.0.0.1:6379 and 127.0.0.2:8990 respectively

Deploy Redis

  1. Clone the setup repo (https://github.com/appveen/setup-redis-cluster)

  2. Update the redis image and port details in redis-sts.yaml and redis-svc.yaml.

  3. If deploying redis without MOUNT , remove the below one from redis-sts.yaml


Volume Mount:- name: data

     mountPath: /data

     readOnly: false

Volumes:

     - name: data

     hostPath:

path: /mnt/redis


  1. Execute install.sh from the downloaded repo. (Specify the k8s namespace and cluster size as prompted). 

  2. Minimum size: 6. Master - 3 and slave -3

  3. Once install.sh has executed successfully, we can see the pods created like below
    redis-cluster-0, redis-cluster-1 … redis-cluster-5 .

Setting up Redis-Cluster

Now, we are going to set up a cluster by executing the below commands one by one.

Replace the _namespace_ with yours.

  1. Get the  IP  address of the redis-cluster pods.

    kubectl get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ' -n _namespace_


  1. Create a cluster between the pods.

kubectl exec -it redis-cluster-0 -n _namespace_ -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ' -n _namespace_)


  1. Get the cluster information

kubectl exec -it -n _namespace_ redis-cluster-0 -- redis-cli cluster info


  1. Verify the master and slaves are connected successfully.

for x in $(seq 0 5); do echo "redis-cluster-$x"; kubectl exec redis-cluster-$x -n _namespace_ -- redis-cli role; echo; done

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article