Redis-Cluster on Kubernetes: Hands-on Guide ③


Failover test

🖧 1. Redis-Cluster Pod diagram (initial state)

┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟢Redis-0(231) │ │🟢Redis-1(233) │ │🟢Redis-2(235) │ │ Master-1 │ │ Master-2 │ │ Master-3 │ └──────┬─────────┘ └──────┬─────────┘ └──────┬────────┘ │ │ │ │ ┌──────────────────│────────────────────┘ │ │ └────────────────────┐ └──────────────────┐ │ │ │ │ ▼ ▼ ▼ ┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟡Redis-3(237) │ │🟡Redis-4(239) │ │🟡Redis-5(241) │ │ Replica-1 │ │ Replica-2 │ │ Replica-3 │ └────────────────┘ └────────────────┘ └───────────────┘

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)

💻 Terminal

💻 Redis-0 LOG: Master -> Replica

① 24s received kill signal, Redis down (+0s)
② 26s Redis auto-restart (+2s)
③ 35s switched Master -> Replica(Slave) (+11s)

💻 Terminal

Redis-0 full log ▼
📄 redis.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.log

💻 Redis-4 LOG: Replica -> Master

① 24s Redis-0 down detected (+0s)
② 29s promoted to master (+5s)

📄 redis.log

Redis-4 full log ▼
📄 redis.log

🧮 State after failover

Redis-0 IP changed from '10.42.0.231' to '10.42.0.242'.

💻 Terminal

🖧 Redis-Cluster Pod diagram (after failover)

┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟡Redis-0(242) │ │🟢Redis-1(233) │ │🟢Redis-2(235) │ │ Replica-2 │ │ Master-2 │ │ Master-3 │ └──────┬─────────┘ └──────┬─────────┘ └──────┬────────┘ ▲ │ │ │ ┌──────────────────│────────────────────┘ │ │ └────────────────────┐ └──────────────────┐ │ │ │ │ ▼ │ ▼ ┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟡Redis-3(237) │ │🟢Redis-4(239) │ │🟡Redis-5(241) │ │ Replica-1 │ │ Master-1 │ │ Replica-3 │ └────────────────┘ └────────────────┘ └───────────────┘

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)

💻 Terminal

💻 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.log

Redis-0 full log ▼
📄 redis.log

💻 Redis-1 LOG: Master

① 56s Redis-4 confirmed down (+4s)
② 57s Redis-0 promoted to new master (+5s)

📄 redis.log

💻 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.log

Redis-4 full log ▼
📄 redis.log

🧮 State after failback

Redis-4 IP changed from '10.42.0.239' to '10.42.0.243'.

💻 Terminal

🧮 Check cluster info

💻 Terminal

🧮 Check cluster nodes

💻 Terminal

🖧 Redis-Cluster Pod diagram (after failback)

┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟢Redis-0(242) │ │🟢Redis-1(233) │ │🟢Redis-2(235) │ │ Master-1 │ │ Master-2 │ │ Master-3 │ └──────┬─────────┘ └──────┬─────────┘ └──────┬────────┘ │ │ │ │ ┌──────────────────│────────────────────┘ │ │ └────────────────────┐ └──────────────────┐ │ │ │ │ ▼ ▼ ▼ ┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟡Redis-3(237) │ │🟡Redis-4(243) │ │🟡Redis-5(241) │ │ Replica-1 │ │ Replica-2 │ │ Replica-3 │ └────────────────┘ └────────────────┘ └───────────────┘

🧑‍💻 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

💻 Terminal

💻 Redis-0 LOG: Master -> Replica

① 17s SLEEP started (+0s)
② 27s SLEEP ended (+10s)
③ 27s switched Master -> Replica (+10s)

📄 redis.log

Redis-0 full log ▼
📄 redis.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.log

💻 Redis-4 LOG: Replica -> Master

① 21s Redis-0 confirmed down (Fail/odown) (+4s)
② 22s switched Replica -> Master (+5s)

📄 redis.log

Redis-4 full log ▼
📄 redis.log

🧮 State after failover

The IP does not change. The Pod itself stays alive. See the 'AGE' column.

💻 Terminal

🧮 cluster info

💻 Terminal

🧮 cluster nodes

💻 Terminal

🖧 Redis-Cluster Pod diagram (after failover)

┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟡Redis-0(242) │ │🟢Redis-1(233) │ │🟢Redis-2(235) │ │ Replica-2 │ │ Master-2 │ │ Master-3 │ └────────────────┘ └──────┬─────────┘ └──────┬────────┘ ▲ │ │ │ ┌──────────────────│────────────────────┘ │ │ └────────────────────┐ └──────────────────┐ │ │ │ │ ▼ │ ▼ ┌────────────────┐ ┌────┴───────────┐ ┌───────────────┐ │🟡Redis-3(237) │ │🟢Redis-4(243) │ │🟡Redis-5(241) │ │ Replica-1 │ │ Master-1 │ │ Replica-3 │ └────────────────┘ └────────────────┘ └───────────────┘

2. Failback test

• Failback test: Redis-4 Sleep 10 -> confirm Redis-0 switches (promotes) from Replica to Master

💻 Redis-4 SLEEP 10

💻 Terminal

💻 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.log

Redis-0 full log ▼
📄 redis.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.log

💻 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.log

Redis-4 full log ▼
📄 redis.log

🧮 State after failback

💻 Terminal

🧮 cluster info

💻 Terminal

🧮 cluster nodes

💻 Terminal

🖧 Redis-Cluster Pod diagram (after failback)

┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟢Redis-0(242) │ │🟢Redis-1(233) │ │🟢Redis-2(235) │ │ Master-1 │ │ Master-2 │ │ Master-3 │ └──────┬─────────┘ └──────┬─────────┘ └──────┬────────┘ │ │ │ │ ┌──────────────────│────────────────────┘ │ │ └────────────────────┐ └──────────────────┐ │ │ │ │ ▼ ▼ ▼ ┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟡Redis-3(237) │ │🟡Redis-4(243) │ │🟡Redis-5(241) │ │ Replica-1 │ │ Replica-2 │ │ Replica-3 │ └────────────────┘ └────────────────┘ └───────────────┘


🧑‍💻 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 ① >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.