k8s_redis_cluster_2
Redis-Cluster on Kubernetes: Hands-on Guide ②
Setup (create Pods)
1. Apply YAML files in order (create)
1) Create Config
2) Create Service
3) Create StatefulSet
At this point six standalone Redis instances are running. Redis-Cluster is not formed yet.
2. Form Redis-Cluster
1) Write and run the Redis-Cluster create script
Running 'cluster_create.sh' forms Redis-Cluster with 3 Masters and 3 Replicas.
🧑💻 Key points
- On a VM you write IP:Port; on Kubernetes you write the following.
redis-cluster-0.${SERVICE_NAME}.${NAMESPACE}.svc.cluster.local:${PORT}
List redis-cluster-0 through 5. - --cluster-replicas 1 # Set Master 1 -> Replica 1.
- --cluster-yes # This option auto-answers 'yes' to the prompt below.
Can I set the above configuration? (type 'yes' to accept): yes
Without this option you must type 'yes'.
🖧 Redis Cluster create process
📍 Slots were assigned evenly to 3 Masters.
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
📍 Replica -> Master relationship
Adding replica redis-cluster-4 to redis-cluster-0
Adding replica redis-cluster-5 to redis-cluster-1
Adding replica redis-cluster-3 to redis-cluster-2
📍 OK success! All slots are covered.
[OK] All 16384 slots covered.
View full output
2) cluster info
3) cluster nodes
Shown in node order for convenience. Actual output is random.
Same content as nodes.conf.
3. 🖧 Redis-Cluster Pod diagram
4. 💽 Load data
If you down (delete) the Redis-0 Pod for a failover test, Kubernetes brings redis-0 back within 2 seconds. cluster-node-timeout is 3 seconds, so the down of Redis-0 is not detected. So we load about 10 million keys so restart takes more than 5 seconds.
1) Verify loaded data
① Keys per node: dbsize
② Check AOF file size
③ Check memory
➡ Pods are up and data is loaded. Let’s run the failover test.
| << K8s Redis-Cluster Prep ① | K8s Redis-Cluster Test ③ >> |
|---|
