github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docs/user_docs/kubeblocks-for-redis/high-availability/high-availability.md (about) 1 --- 2 title: High Availability for Redis 3 description: High availability for a Redis cluster 4 keywords: [redis, high availability] 5 sidebar_position: 1 6 --- 7 8 # High availability 9 10 KubeBlocks integrates [the official Redis Sentinel solution](https://redis.io/docs/management/sentinel/) to realize high availability and adopts Noop as the switch policy. 11 12 Redis Sentinel is the high availability solution for a Redis Replication Cluster, which is recommended by Redis and is also the main-stream solution in the community. 13 14 In the RedisReplication Cluster provided by KubeBlocks, Sentinel is deployed as an independent component. 15 16 ## Before you start 17 18 * Install KubeBlocks: You can install KubeBlocks by [kbcli](./../../installation/install-with-kbcli/install-kubeblocks-with-kbcli.md) or by [Helm](./../../installation/install-with-helm/install-kubeblocks-with-helm.md). 19 * [Create a Redis Replication Cluster](./../cluster-management/create-and-connect-a-redis-cluster.md#create-a-redis-cluster). 20 * Check the Switch Policy and the role probe. 21 * Check whether the switch policy is `Noop`. 22 23 ```bash 24 kubectl get cluster redis-cluster -o yaml 25 > 26 spec: 27 componentSpecs: 28 - name: redis 29 componentDefRef: redis 30 switchPolicy: 31 type: Noop 32 ``` 33 34 * Check whether the following role probe parameters exist to verify the role probe is enabled. 35 36 ```bash 37 kubectl get cd redis -o yaml 38 > 39 probes: 40 roleProbe: 41 failureThreshold: 3 42 periodSeconds: 2 43 timeoutSeconds: 1 44 ``` 45 46 ## Steps 47 48 1. View the initial status of the Redis cluster. 49 50 ```bash 51 kbcli cluster describe redis-cluster 52 ``` 53 54  55 56 Currently, `redis-cluster-redis-0` is the primary pod and `redis-cluster-redis-1` is the secondary pod. 57 58 2. Simulate a primary pod exception. 59 60 ```bash 61 # Enter the primary pod 62 kubectl exec -it redis-cluster-redis-0 -- bash 63 64 # Execute the debug sleep command to simulate a primary pod exception 65 root@redis-redis-0:/# redis-cli debug sleep 30 66 ``` 67 68 3. Open the Redis Sentinel log to view the failover. 69 70 ```bash 71 kubectl logs redis-cluster-redis-sentinel-0 72 ``` 73 74 In the logs, we can view when a high-availability switch occurs. 75 76 ```bash 77 1:X 18 Apr 2023 06:13:17.072 # +switch-master redis-cluster-redis-sentinel redis-cluster-redis-0.redis-cluster-redis-headless.default.svc 6379 redis-cluster-redis-1.redis-cluster-redis-headless.default.svc 6379 78 1:X 18 Apr 2023 06:13:17.074 * +slave slave redis-cluster-redis-0.redis-cluster-redis-headless.default.svc:6379 redis-cluster-redis-0.redis-cluster-redis-headless.default.svc 6379 @ redis-cluster-redis-sentinel redis-cluster-redis-1.redis-cluster-redis-headless.default.svc 6379 79 1:X 18 Apr 2023 06:13:17.077 * Sentinel new configuration saved on disk 80 ``` 81 82 4. Connect to the Redis cluster to view the primary pod information after the exception simulation. 83 84 ```bash 85 kbcli cluster connect redis-cluster 86 ``` 87 88 ```bash 89 # View the current primary pod 90 127.0.0.1:6379> info replication 91 ``` 92 93  94 95 From the output, `redis-cluster-redis-1` has been assigned as the secondary's pod. 96 97 5. Describe the cluster and check the instance role. 98 99 ```bash 100 kbcli cluster describe redis-cluster 101 ``` 102 103  104 105 After the failover, `redis-cluster-redis-0` becomes the secondary pod and `redis-cluster-redis-1` becomes the primary pod.