Prerequisites
Redis cluster supported from version 1.2.4 in @appveen/utils (https://github.com/appveen/utils)
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
Clone the setup repo (https://github.com/appveen/setup-redis-cluster)
Update the redis image and port details in redis-sts.yaml and redis-svc.yaml.
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
Execute install.sh from the downloaded repo. (Specify the k8s namespace and cluster size as prompted).
Minimum size: 6. Master - 3 and slave -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.
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_
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_)
Get the cluster information
kubectl exec -it -n _namespace_ redis-cluster-0 -- redis-cli cluster info
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
Feedback sent
We appreciate your effort and will try to fix the article