k8s_redis_sentinel_sidecar_3
Redis-Sentinel Sidecar Pattern Hands-on Guide on Kubernetes ③
Failover test
🖧 1. Redis-Sentinel Pod diagram (initial)
1. Failover test
Take Redis-0 down and confirm Redis-1 is promoted from replica to master
- Why Redis-1 becomes master among replicas 1 and 2:
replica-priority: Redis-0=100, Redis-1=110, Redis-2=120
-> lower value wins, so Redis-1 is promoted.
- Redis and Sentinel share Pod-0, so they go down together.
💥 After restart both Redis and Sentinel IPs change.
Pod-0 (Redis-0/Sentinel-0) 💥 down (delete)
💻 Redis-0 LOG: Master -> Replica
① 27s: got kill signal, Redis down (+0s)
② 30s: Redis auto-restart (+3s)
③ 43s: Sentinel command, Master -> Replica (+16s)
Full Redis-0 log
💻 Redis-1 LOG: Replica -> Master
① 27s: detect Redis-0 down (connection lost) (+0s)
② 31s: Sentinel replicaof no one, Replica -> Master (+4s)
Full Redis-1 log
💻 Redis-2 LOG: Replica
① 27s: detect Redis-0 down (connection lost) (+0s)
② 32s: connect to new master Redis-1 (+5s)
Full Redis-2 log
💻 Sentinel-0 LOG
① 27s: kill signal, Sentinel down (+0s)
② 30s: Sentinel auto-restart (+3s)
③ 34s: start monitoring Redis-1 (+7s)
Full Sentinel-0 log
💻 Sentinel-1 LOG
① 27s: Redis-0 connection lost (+0s)
② 30s: +sdown on Redis-0 (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
③ 31s: +odown on Redis-0 (+4s) -> after majority of Sentinels agree
④ 43s: notify Redis-0 that Redis-1 is master (+16s)
Full Sentinel-1 log
💻 Sentinel-2 LOG
① 27s: Redis-0 connection lost (+0s)
② 30s: +sdown on Redis-0 (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
③ 30s: +odown on Redis-0 (+3s) -> after majority of Sentinels agree
③ 30s: Sentinels elect Sentinel-2 as leader (+elected-leader) (+3s)
④ 31s: promote Redis-1 (+failover-state-send-slaveof-noone) (+4s)
Full Sentinel-2 log
🧮 After failover
Redis-0 IP changed from 10.42.0.106 to 10.42.0.111.
💾 Check redis.conf
Check replicaof
💾 Check sentinel.conf
Redis-1 is master; Redis-0 and Redis-2 are replicas.
🖧 Redis-Sentinel Pod diagram (after failover)
2. Failback test
Take current master Redis-1 down and confirm Redis-0 is promoted back to master
📚 “Failback test” here means making Redis-0 master again.
(Named to distinguish it from the failover test.)
💻 Redis-1 💥 down (delete)
💻 Redis-0 LOG: Replica -> Master
① 15s: Redis-1 connection lost (+1s)
② 18s: Sentinel command, Replica -> Master (+4s)
Full Redis-0 log
💻 Redis-1 LOG: Master -> Replica
① 14s: got kill signal, down (+0s)
② 17s: Pod restart (+3s)
③ 29s: Sentinel command, Master -> Replica (+15s)
Full Redis-1 log
💻 Redis-2 LOG
① 15s: lost Redis-1 (+1s)
② 19s: Sentinel: Redis-0 is new master; connect (+5s)
Full Redis-2 log
💻 Sentinel-0 LOG
① 14s: Redis-1 connection lost (+0s)
② 17s: +sdown on Redis-1 (+3s) -> sentinel.conf down-after-milliseconds mymaster 3000 ms
② 19s: +odown on Redis-1 (+5s) -> after majority of Sentinels agree
Full Sentinel-0 log
💻 Sentinel-1 LOG
① 14s: got kill signal, down (+0s)
② 17s: Pod restart (+3s)
Full Sentinel-1 log
💻 Sentinel-2 LOG: elected leader
① 14s: lost Redis-1 (+0s)
② 17s: detect Redis-1 down (+3s)
③ 18.7s: confirm Redis-1 down (+4s)
④ 18.8s: Sentinels elect Sentinel-2 as leader (+elected-leader) (+4s)
④ 18.8s: promote redis-0 (+failover-state-send-slaveof-noone) (+4s)
Full Sentinel-2 log
🧮 After failback
Redis-1 IP changed from 10.42.0.108 to 10.42.0.112.
💾 Check redis.conf
💾 Check sentinel.conf
Redis-0 is master; Redis-1 and Redis-2 are replicas.
🖧 Redis-Sentinel Pod diagram (after failback)
| << K8s Sidecar Pattern Setup ② | K8s Redis-Standalone ① >> |
|---|
