k8s_redis_cluster_3
Redis-Cluster on Kubernetes: Hands-on Guide ③
Failover test
🖧 1. Redis-Cluster Pod diagram (initial state)
1. Failover test
Take Redis-0 Pod down and confirm Redis-4 switches (promotes) from Replica to Master
The redis.conf replica-priority value is not used in Redis-Cluster.
It is used in Redis-Sentinel.
Instead, the replica that received the newest data becomes master.
Here each master has one replica, so Redis-4 (replica of Redis-0) becomes master.
💥 After a Pod is taken down and restarted, its IP changes.
Redis-0 💥 down (delete)
💻 Redis-0 LOG: Master -> Replica
① 24s received kill signal, Redis down (+0s)
② 26s Redis auto-restart (+2s)
③ 35s switched Master -> Replica(Slave) (+11s)
Redis-0 full log
💻 Redis-1 LOG: Master
① 28s Redis-0 confirmed down (Fail/odown) (+4s) -> cluster-node-timeout 3000ms
② 29s Redis-4 promoted to new master (+5s)
💻 Redis-4 LOG: Replica -> Master
① 24s Redis-0 down detected (+0s)
② 29s promoted to master (+5s)
Redis-4 full log
🧮 State after failover
Redis-0 IP changed from '10.42.0.231' to '10.42.0.242'.
🖧 Redis-Cluster Pod diagram (after failover)
2. Failback test
Take current master Redis-4 down and confirm Redis-0 switches (promotes) from Replica to Master
📚 'Failback test' is used here to mean making the Redis-0 Pod master again.
(Used to distinguish it from the failover test)
💻 Redis-4 💥 down (delete)
💻 Redis-0 LOG: Replica -> Master
① 52s connection to Redis-4 lost (+0s)
② 56s Redis-4 confirmed down (Fail/odown) (+4s)
③ 57s switched Replica -> Master (promoted) (+5s)
Redis-0 full log
💻 Redis-1 LOG: Master
① 56s Redis-4 confirmed down (+4s)
② 57s Redis-0 promoted to new master (+5s)
💻 Redis-4 LOG: Master -> Replica
① 19m 52s received kill signal and went down (+0s)
② 19m 54s Pod (Redis) restarted (+2s)
③ 20m 02s switched Master -> Replica(Slave) (+10s)
Redis-4 full log
🧮 State after failback
Redis-4 IP changed from '10.42.0.239' to '10.42.0.243'.
🧮 Check cluster info
🧮 Check cluster nodes
🖧 Redis-Cluster Pod diagram (after failback)
🧑💻 Conclusion
Redis-Cluster failover and failback tests succeeded
Taking a Pod down and restarting it changes the IP, and it is handled without issues.
Failover test: Redis-0 SLEEP (pause)
The SLEEP test creates a situation where Redis cannot respond for any reason,
and checks whether failover still works correctly.
💥 'Sleep 10' pauses Redis for 10 seconds, so the IP does not change.
1. Failover test
• Failover test: Redis-0 Sleep 10 -> confirm Redis-4 switches (promotes) from Replica to Master
Redis-0 SLEEP 10
💻 Redis-0 LOG: Master -> Replica
① 17s SLEEP started (+0s)
② 27s SLEEP ended (+10s)
③ 27s switched Master -> Replica (+10s)
Redis-0 full log
💻 Redis-1 LOG: Master
① 21s Redis-0 confirmed down (Fail/odown) (+4s) -> cluster-node-timeout 3000ms
② 22s Redis-4 switched Replica -> Master (+5s)
③ 27s Redis-0 restarted (+10s)
💻 Redis-4 LOG: Replica -> Master
① 21s Redis-0 confirmed down (Fail/odown) (+4s)
② 22s switched Replica -> Master (+5s)
Redis-4 full log
🧮 State after failover
The IP does not change. The Pod itself stays alive. See the 'AGE' column.
🧮 cluster info
🧮 cluster nodes
🖧 Redis-Cluster Pod diagram (after failover)
2. Failback test
• Failback test: Redis-4 Sleep 10 -> confirm Redis-0 switches (promotes) from Replica to Master
💻 Redis-4 SLEEP 10
💻 Redis-0 LOG: Replica -> Master
① 26s SLEEP command executed (+0s)
② 30s Redis-4 confirmed down (Fail/odown) (+4s)
③ 31s Redis-0 switched Replica -> Master (+5s)
④ 36s Redis-4 restarted (+10s)
Redis-0 full log
💻 Redis-1 LOG: Master
① 30s Redis-4 confirmed down (Fail/odown) (+4s)
② 31s Redis-0 switched Replica -> Master (promoted) (+5s)
③ 36s Redis-4 restarted (+10s)
💻 Redis-2 LOG: same as Redis-1 log, omitted
💻 Redis-4 LOG: Master -> Replica
① 26s SLEEP command executed (+0s)
① 36s SLEEP command ended -> connection with replica (Redis-0) lost (+10s)
② 36s switched Master -> Replica (+10s)
Redis-4 full log
🧮 State after failback
🧮 cluster info
🧮 cluster nodes
🖧 Redis-Cluster Pod diagram (after failback)
🧑💻 Conclusion
Redis-Cluster failover and failback tests using SLEEP succeeded
With SLEEP, Redis does not go down and the IP does not change, but
if there is no response for more than 3 seconds, failover runs.
➡ So far we tested Redis-Cluster by itself.
Click here to see it working with a Java (Spring) App.
| << K8s Redis-Cluster Setup ② | K8s Redis-Cluster App ① >> |
|---|
