mirror of
https://github.com/wahyd4/docker-images.git
synced 2026-08-09 04:46:45 +10:00
3.9 KiB
3.9 KiB
This images is aim to make you create a 6 node Redis cluster in minutes
Create a Redis cluster on Kubernetes
- Create a k8s deployment with Redis cluster mode.
kubectl run redis --image=registry.cn-hangzhou.aliyuncs.com/junv/cluster-redis:latest --command /usr/local/bin/redis-server /root/redis.conf
- Expose the port if you want (optional)
kubectl expose deployment redis --type=NodePort --port=6379
- Scale up 6 pods
kubectl scale deployments redis --replicas=6
- Take a look at the redis pods
kubectl get pods -o wide | grep redis
redis-3960932871-2q6r1 1/1 Running 0 27m 172.17.0.11 minikube
redis-3960932871-6383l 1/1 Running 0 28m 172.17.0.16 minikube
redis-3960932871-dktnt 1/1 Running 0 27m 172.17.0.14 minikube
redis-3960932871-qktzm 1/1 Running 0 27m 172.17.0.12 minikube
redis-3960932871-tlgw3 1/1 Running 0 28m 172.17.0.15 minikube
redis-3960932871-x5k06 1/1 Running 0 27m 172.17.0.13 minikube
- Access a Redis pod, pick anyone you like.
kubectl exec -it redis-3960932871-2q6r1 bash
- Go to Redis source code folder
cd /usr/src/redis/src/
- Create the Redis cluster (You should type all the IPs of six pods)
./redis-trib.rb create --replicas 1 172.17.0.11:6379 172.17.0.12:6379 172.17.0.13:6379 \
172.17.0.14:6379 172.17.0.15:6379 172.17.0.16:6379
- Type "yes" when you saw this
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.244.1.131:6379
10.244.8.165:6379
10.244.8.163:6379
Adding replica 10.244.8.164:6379 to 10.244.1.131:6379
Adding replica 10.244.1.129:6379 to 10.244.8.165:6379
Adding replica 10.244.1.130:6379 to 10.244.8.163:6379
M: 0282dc6d88992d33bc4423f4a36436b4e465b42d 10.244.1.131:6379
slots:0-5460 (5461 slots) master
M: e1786c92ae16c92bd122fb614b80920a88bddc94 10.244.8.165:6379
slots:5461-10922 (5462 slots) master
M: 9268d2a235026a4acfaaf9d3e969ec7a559d6e9b 10.244.8.163:6379
slots:10923-16383 (5461 slots) master
S: dd26e888f3010850f1f2499b20fef6bce0e89122 10.244.8.164:6379
replicates 0282dc6d88992d33bc4423f4a36436b4e465b42d
S: 865583db4ee9a68acea1c2d81f89456a6c8bfb68 10.244.1.129:6379
replicates e1786c92ae16c92bd122fb614b80920a88bddc94
S: a76cae8dcde6e55f70e5f96f589ea1520d2c3f4b 10.244.1.130:6379
replicates 9268d2a235026a4acfaaf9d3e969ec7a559d6e9b
Can I set the above configuration? (type 'yes' to accept): yes
When you see something like the following, then all done!
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
- You can verify it by
redis-cli
127.0.0.1:6379> cluster nodes
127.0.0.1:6379> cluster nodes
9268d2a235026a4acfaaf9d3e969ec7a559d6e9b 10.244.8.163:6379 master - 1498813397795 1498813395292 3 connected 10923-16383
865583db4ee9a68acea1c2d81f89456a6c8bfb68 10.244.1.129:6379 slave e1786c92ae16c92bd122fb614b80920a88bddc94 1498813399298 1498813397194 5 connected
e1786c92ae16c92bd122fb614b80920a88bddc94 10.244.8.165:6379 master - 1498813397295 1498813394790 2 connected 5461-10922
a76cae8dcde6e55f70e5f96f589ea1520d2c3f4b 10.244.1.130:6379 slave 9268d2a235026a4acfaaf9d3e969ec7a559d6e9b 1498813398296 1498813396292 6 connected
dd26e888f3010850f1f2499b20fef6bce0e89122 10.244.8.164:6379 master - 1498813396793 1498813394290 7 connected 0-5460
0282dc6d88992d33bc4423f4a36436b4e465b42d 10.244.1.131:6379 myself,slave dd26e888f3010850f1f2499b20fef6bce0e89122 0 0 1 connected
(0.60s)
Others
I followed the Redis official cluster tutorial to build this custom redis image(upon redis-3.2.9) and set up the cluster. Please check at https://redis.io/topics/cluster-tutorial