k8s_redis_sentinel_3
Redis-Sentinel on Kubernetes Test ③
Failover test
🖧 Redis-Sentinel Pod diagram (initial state)
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)
💻 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-0 full 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-1 full log
💻 Redis-2 LOG
① 03s detects Redis-0 down (+0s)
② 07s connects to the new master (Redis-1) (+4s)
Redis-2 full 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-0 full 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-1 full 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-2 full log
🧮 State after failover
redis-0 IP changed from '10.42.0.92' to '10.42.0.103'.
🧮 Check redis.conf
Redis LOG: changed during 'CONFIG REWRITE'.
🧮 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.
🖧 Redis-Sentinel Pod diagram (after failover)
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)
💻 Redis-0 LOG: Replica -> Master
① 29m 55s Redis-1 connection lost (+0s)
② 29m 58s command from Sentinel, Replica(Slave) -> Master (+3s)
Redis-0 full 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-1 full 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-2 full 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-0 full 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-1 full 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-2 full log
🧮 State after failback
🧮 Check redis.conf
🧮 Check sentinel.conf
Redis-0 master, Redis-1,2 replicas
🖧 Redis-Sentinel Pod diagram (failback)
🧑💻 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 ① >> |
|---|
