Skip to main content
Version: Preview

Create and Connect to a Redis cluster

This tutorial shows how to create and connect to a Redis cluster.

Create a Redis cluster

Before you start

  • Install kbcli if you want to create a Redis cluster by kbcli.

  • Install KubeBlocks by kbcli or by Helm.

  • Make sure the Redis Addon is enabled. The Redis Addon is enabled by KubeBlocks by default. If you disable it when installing KubeBlocks, enable it first.

    kbcli addon list
    >
    NAME TYPE STATUS EXTRAS AUTO-INSTALL
    ...
    redis Helm Enabled true
    ...
  • View all the database types and versions available for creating a cluster.

    kbcli clusterdefinition list
    >
    NAME TOPOLOGIES SERVICEREFS STATUS AGE
    redis replication,replication-twemproxy,standalone Available 16m

    kbcli clusterversion list
    >
    NAME CLUSTER-DEFINITION STATUS IS-DEFAULT CREATED-TIME
    redis-7.0.6 redis Available false Sep 27,2024 11:36 UTC+0800
    redis-7.2.4 redis Available false Sep 27,2024 11:36 UTC+0800
  • To keep things isolated, create a separate namespace called demo throughout this tutorial.

    kubectl create namespace demo
    >
    namespace/demo created

Create a cluster

KubeBlocks supports creating two types of Redis clusters: Standalone and Replication Cluster. Standalone only supports one replica and can be used in scenarios with lower requirements for availability. For scenarios with high availability requirements, it is recommended to create a Replication Cluster, which supports automatic failover. To ensure high availability, Primary and Secondary are distributed on different nodes by default.

  1. Create an Redis cluster.

    kbcli cluster create redis mycluster -n demo

    If you want to customize your cluster specifications, kbcli provides various options, such as setting cluster version, termination policy, CPU, and memory. You can view these options by adding --help or -h flag.

    kbcli cluster create redis --help

    kbcli cluster create redis -h
  2. Verify whether this cluster is created successfully.

    kbcli cluster list -n demo
    >
    NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME
    mycluster demo redis Delete Running Sep 29,2024 09:46 UTC+0800

Connect to a Redis Cluster

kbcli cluster connect mycluster -n demo

For the detailed database connection guide, refer to Connect database.