Redis-Cluster on Kubernetes: Hands-on Guide ②


Setup (create Pods)

1. Apply YAML files in order (create)

1) Create Config

💻 Terminal

2) Create Service

💻 Terminal

3) Create StatefulSet

💻 Terminal

At this point six standalone Redis instances are running. Redis-Cluster is not formed yet.

2. Form Redis-Cluster

1) Write and run the Redis-Cluster create script

Running 'cluster_create.sh' forms Redis-Cluster with 3 Masters and 3 Replicas.

💻 Terminal


🧑‍💻 Key points

  • On a VM you write IP:Port; on Kubernetes you write the following.
    redis-cluster-0.${SERVICE_NAME}.${NAMESPACE}.svc.cluster.local:${PORT}
    List redis-cluster-0 through 5.
  • --cluster-replicas 1 # Set Master 1 -> Replica 1.
  • --cluster-yes # This option auto-answers 'yes' to the prompt below.
    Can I set the above configuration? (type 'yes' to accept): yes
    Without this option you must type 'yes'.

🖧 Redis Cluster create process

📍 Slots were assigned evenly to 3 Masters.
      Master[0] -> Slots 0 - 5460
      Master[1] -> Slots 5461 - 10922
      Master[2] -> Slots 10923 - 16383
📍 Replica -> Master relationship
      Adding replica redis-cluster-4 to redis-cluster-0
      Adding replica redis-cluster-5 to redis-cluster-1
      Adding replica redis-cluster-3 to redis-cluster-2
📍 OK success! All slots are covered.
      [OK] All 16384 slots covered.

View full output ▼
💻 Terminal

2) cluster info

💻 Terminal

3) cluster nodes

Shown in node order for convenience. Actual output is random.
Same content as nodes.conf.

💻 Terminal

3. 🖧 Redis-Cluster Pod diagram

┌────────────────┐ ┌────────────────┐ ┌───────────────┐ │🟢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 │ └────────────────┘ └────────────────┘ └───────────────┘

4. 💽 Load data

If you down (delete) the Redis-0 Pod for a failover test, Kubernetes brings redis-0 back within 2 seconds. cluster-node-timeout is 3 seconds, so the down of Redis-0 is not detected. So we load about 10 million keys so restart takes more than 5 seconds.

💻 Terminal

1) Verify loaded data

① Keys per node: dbsize

💻 Terminal

② Check AOF file size
💻 Terminal

③ Check memory
💻 Terminal


➡ Pods are up and data is loaded. Let’s run the failover test.


<< K8s Redis-Cluster Prep ① K8s Redis-Cluster Test ③ >>

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