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
Make sure the Redis addon is enabled. If this addon is not enabled, 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
kbcli clusterversion listTo 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.
Create a Standalone.
kbcli cluster create --cluster-definition redis --set replicas=1 <clustername>
Create a Replication Cluster.
kbcli cluster create --cluster-definition redis --set replicas=2 <clustername>
If you only have one node for deploying a Replication, set the topology-keys
as null
when creating a Replication Cluster.
kbcli cluster create --cluster-definition redis --set replicas=2 --topology-keys null <clustername>
If you want to specify a cluster version, you can first view the available versions and use --version
to specify a version.
kbcli clusterversion list
kbcli cluster create --cluster-definition redis --version redis-7.2.4 <clustername>
In the production environment, it is not recommended to deploy all replicas on one node, which may decrease the cluster availability.
View more flags for creating a cluster to create a cluster with customized specifications.
kbcli cluster create --help
Connect to a Redis Cluster
kbcli cluster connect <clustername> --namespace <name>
For the detailed database connection guide, refer to Connect database.