Redis-Sentinel Sidecar Pattern Hands-on Guide on Kubernetes ③


Failover test

🖧 1. Redis-Sentinel Pod diagram (initial)

┌─────────────────┐ │ Redis-0(106) │ │ 🟢Master │ │ Sentinel-0 │ └───────┬─────────┘ ┌───────────┴──────────┐ ▼ ▼ ┌─────────────────┐ ┌─────────────────┐ │ Redis-1(108) │ │ Redis-2(110) │ │ 🟡Replica-1 │ │ 🟡Replica-2 │ │ Sentinel-1 │ │ Sentinel-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 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)

💻 Terminal

💻 Redis-0 LOG: Master -> Replica

① 27s: got kill signal, Redis down (+0s)
② 30s: Redis auto-restart (+3s)
③ 43s: Sentinel command, Master -> Replica (+16s)

📄 redis.log

Full Redis-0 log ▼
📄 redis.log

💻 Redis-1 LOG: Replica -> Master

① 27s: detect Redis-0 down (connection lost) (+0s)
② 31s: Sentinel replicaof no one, Replica -> Master (+4s)

📄 redis.log

Full Redis-1 log ▼
📄 redis.log

💻 Redis-2 LOG: Replica

① 27s: detect Redis-0 down (connection lost) (+0s)
② 32s: connect to new master Redis-1 (+5s)

📄 redis.log

Full Redis-2 log ▼
📄 redis.log

💻 Sentinel-0 LOG

① 27s: kill signal, Sentinel down (+0s)
② 30s: Sentinel auto-restart (+3s)
③ 34s: start monitoring Redis-1 (+7s)

📄 redis.log

Full Sentinel-0 log ▼
📄 redis.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)

📄 redis.log

Full Sentinel-1 log ▼
📄 redis.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)

📄 redis.log

Full Sentinel-2 log ▼
📄 redis.log

🧮 After failover

Redis-0 IP changed from 10.42.0.106 to 10.42.0.111.

💻 Terminal

💾 Check redis.conf

Check replicaof

📄 redis.conf

💾 Check sentinel.conf

Redis-1 is master; Redis-0 and Redis-2 are replicas.

📄 sentinel.conf

🖧 Redis-Sentinel Pod diagram (after failover)

┌─────────────────┐ │ Redis-0(111) │ │ 🟡Replica-1 │ │ Sentinel-0 │ └───────┬─────────┘ ▲ ┌───────────┴──────────┐ │ ▼ ┌─────────────────┐ ┌─────────────────┐ │ Redis-1(108) │ │ Redis-2(110) │ │ 🟢Master │ │ 🟡Replica-2 │ │ Sentinel-1 │ │ Sentinel-2 │ └─────────────────┘ └─────────────────┘

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)

💻 Terminal

💻 Redis-0 LOG: Replica -> Master

① 15s: Redis-1 connection lost (+1s)
② 18s: Sentinel command, Replica -> Master (+4s)

📄 redis.log

Full Redis-0 log ▼
📄 redis.log

💻 Redis-1 LOG: Master -> Replica

① 14s: got kill signal, down (+0s)
② 17s: Pod restart (+3s)
③ 29s: Sentinel command, Master -> Replica (+15s)

📄 redis.log

Full Redis-1 log ▼
📄 redis.log

💻 Redis-2 LOG

① 15s: lost Redis-1 (+1s)
② 19s: Sentinel: Redis-0 is new master; connect (+5s)

📄 redis.log

Full Redis-2 log ▼
📄 redis.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

📄 redis.log

Full Sentinel-0 log ▼
📄 redis.log

💻 Sentinel-1 LOG

① 14s: got kill signal, down (+0s)
② 17s: Pod restart (+3s)

📄 redis.log

Full Sentinel-1 log ▼
📄 redis.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)

📄 redis.log

Full Sentinel-2 log ▼
📄 redis.log

🧮 After failback

Redis-1 IP changed from 10.42.0.108 to 10.42.0.112.

💻 Terminal

💾 Check redis.conf

📄 redis.conf

💾 Check sentinel.conf

Redis-0 is master; Redis-1 and Redis-2 are replicas.

📄 sentinel.conf

🖧 Redis-Sentinel Pod diagram (after failback)

┌─────────────────┐ │ Redis-0(111) │ │ 🟢Master │ │ Sentinel-0 │ └───────┬─────────┘ ┌───────────┴──────────┐ ▼ ▼ ┌─────────────────┐ ┌─────────────────┐ │ Redis-1(112) │ │ Redis-2(110) │ │ 🟡Replica-1 │ │ 🟡Replica-2 │ │ Sentinel-1 │ │ Sentinel-2 │ └─────────────────┘ └─────────────────┘


<< K8s Sidecar Pattern Setup ② K8s Redis-Standalone ① >>

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