Redis-Sentinel on Kubernetes Test ③


Failover test

🖧 Redis-Sentinel Pod diagram (initial state)

┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │Sentinel-0(98) │ │Sentinel-1(100)│ │Sentinel-2(102)│ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ └───────────────────┼───────────────────┘ ▼ ┌───────────────┐ │ Redis-0(92) │ │ 🟢Master │ └──────┬────────┘ ┌──────────┴───────────┐ ▼ ▼ ┌───────────────┐ ┌───────────────┐ │ Redis-1(94) │ │ Redis-2(96) │ │ 🟡Replica-1 │ │ 🟡Replica-2 │ └───────────────┘ └───────────────┘

1. Failover test

Take Redis-0 down and confirm Redis-1 is promoted from replica to master.
Why Redis-1 becomes master among replicas Redis-1 and Redis-2: redis.conf replica-priority value: Redis-0 100, Redis-1 110, Redis-2 120 -> Redis-1 has the smaller value, so it is promoted to master.
💥 After a Pod is deleted and restarted, its IP changes.

Redis-0 💥 down (delete)

💻 Terminal

💻 Redis-0 LOG: Master -> Replica

① 03s receives kill signal and Redis goes down (+0s)
② 05s Redis auto-restarts (+2s)
③ 17s receives a command from Sentinel and switches Master -> Replica(Slave) (+14s)

📄 redis.log

Redis-0 full log ▼
📄 redis.log

💻 Redis-1 LOG: Replica -> Master

① 03s detects Redis-0 down (+0s)
② 06s receives replicaof noone from Sentinel-1 and switches replica -> master (+3s)

📄 redis.log

Redis-1 full log ▼
📄 redis.log

💻 Redis-2 LOG

① 03s detects Redis-0 down (+0s)
② 07s connects to the new master (Redis-1) (+4s)

📄 redis.log

Redis-2 full log ▼
📄 redis.log

💻 Sentinel-0 LOG

① 06.1s detects redis-0 down (+sdown) (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 06.2s confirms redis-0 down (+odown) (+3s) -> confirmed when a majority of Sentinels agree

📄 sentinel.log

Sentinel-0 full log ▼
📄 sentinel.log

💻 Sentinel-1 LOG

① 06.1s detects redis-0 down (+sdown) (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 06.2s confirms redis-0 down (+odown) (+3s) -> confirmed when a majority of Sentinels agree
③ 06.3s Sentinels vote and elect 'Sentinel-1' as Leader (+elected-leader)
④ 06.4s change redis-1 to master (+failover-state-send-slaveof-noone)

📄 sentinel.log

Sentinel-1 full log ▼
📄 sentinel.log

💻 Sentinel-2 LOG

① 06.1s detects redis-0 down (+sdown) (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 07.2s confirms redis-0 down (+odown) (+4s) -> confirmed when a majority of Sentinels agree

📄 sentinel.log

Sentinel-2 full log ▼
📄 sentinel.log

🧮 State after failover

redis-0 IP changed from '10.42.0.92' to '10.42.0.103'.

💻 Terminal

🧮 Check redis.conf

Redis LOG: changed during 'CONFIG REWRITE'.

📄 redis.conf

🧮 Check sentinel.conf

Sentinel LOG: changed at 'Sentinel new configuration saved on disk'.
records redis-0,2 as replicas; sentinel-0,1,2 contents are the same.

📄 sentinel.conf

🖧 Redis-Sentinel Pod diagram (after failover)

┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │Sentinel-0(98) │ │Sentinel-1(100)│ │Sentinel-2(102)│ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ └─────┬─────────────┴───────────────────┘ │ │ ┌───────────────┐ │ │ Redis-0(103) │ │ │ 🟡Replica-1 │ │ └───────────────┘ │ ▲ │ ┌──────────┴───────────┐ ▼ │ ▼ ┌──────┴────────┐ ┌───────────────┐ │ Redis-1(94) │ │ Redis-2(96) │ │ 🟢Master │ │ 🟡Replica-2 │ └───────────────┘ └───────────────┘

2. Failback test

Take the current master Redis-1 down and confirm Redis-0 is promoted 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-1 💥 down (delete)

💻 Terminal

💻 Redis-0 LOG: Replica -> Master

① 29m 55s Redis-1 connection lost (+0s)
② 29m 58s command from Sentinel, Replica(Slave) -> Master (+3s)

📄 redis.log

Redis-0 full log ▼
📄 redis.log

💻 Redis-1 LOG: Master -> Replica

① 29m 55s down after kill signal (+0s)
② 29m 57s Pod restarts (+2s)
③ 30m 11s command from Sentinel, Master -> Replica(Slave) (+16s)

📄 redis.log

Redis-1 full log ▼
📄 redis.log

💻 Redis-2 LOG

① 29m 55s connection to Redis-1 lost (+0s)
② 29m 59s Sentinel signals Redis-0 is the new master; reconnect (+4s)

📄 redis.log

Redis-2 full log ▼
📄 redis.log

💻 Sentinel-0 LOG

① 58.4s detects redis-1 down (+sdown) (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 58.5s confirms redis-1 down (+odown) (+3s) -> confirmed when a majority of Sentinels agree
③ 58.5s Sentinels vote and elect 'Sentinel-0' as Leader (+elected-leader)
④ 58.6s change redis-0 to master (+failover-state-send-slaveof-noone)

📄 sentinel.log

Sentinel-0 full log ▼
📄 sentinel.log

💻 Sentinel-1 LOG

① 58.5s detects redis-1 down (+sdown) (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 58.6s confirms redis-1 down (+odown) (+3s) -> confirmed when a majority of Sentinels agree

📄 sentinel.log

Sentinel-1 full log ▼
📄 sentinel.log

💻 Sentinel-2 LOG

① 58.3s detects redis-1 down (+sdown) (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 59.4s confirms redis-1 down (+odown) (+3s) -> confirmed when a majority of Sentinels agree

📄 sentinel.log

Sentinel-2 full log ▼
📄 sentinel.log

🧮 State after failback

💻 Terminal

🧮 Check redis.conf

📄 redis.conf

🧮 Check sentinel.conf

Redis-0 master, Redis-1,2 replicas

📄 sentinel.conf

🖧 Redis-Sentinel Pod diagram (failback)

┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │Sentinel-0(98) │ │Sentinel-1(100)│ │Sentinel-2(102)│ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ └───────────────────┼───────────────────┘ ▼ ┌───────────────┐ │ Redis-0(103) │ │ 🟢Master │ └──────┬────────┘ ┌──────────┴───────────┐ ▼ ▼ ┌───────────────┐ ┌───────────────┐ │ Redis-1(104) │ │ Redis-2(96) │ │ 🟡Replica-1 │ │ 🟡Replica-2 │ └───────────────┘ └───────────────┘

🧑‍💻 Conclusion

Redis-Sentinel failover and failback tests succeeded
Deleting and restarting a Pod changes its IP, and it is handled without issues.
Failover (recovery) takes about 4 seconds.


➡ So far we tested Redis-Sentinel by itself.
Click here to see it working with a Java (Spring) app.



<< K8s Redis-Sentinel Setup ② K8s Redis-Sentinel App ① >>

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