Operations
Backup And Restores
Custom Secret
Monitoring
tpl
Redis Cluster distributes data across multiple nodes (shards) using hash-based partitioning, allowing horizontal scaling for both reads and writes.
Use Cases
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
To create a redis sharding cluster (cluster mode) with 3 shards, and 2 replica for each shard:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: redis-sharding
namespace: demo
spec:
terminationPolicy: Delete
shardings:
- name: shard
shards: 3
template:
name: redis
componentDef: redis-cluster-7
disableExporter: true
replicas: 2
resources:
limits:
cpu: '1'
memory: 1Gi
requests:
cpu: '1'
memory: 1Gi
serviceVersion: 7.2.4
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
services:
- name: redis-advertised # This is a per-pod svc, and will be used to parse advertised endpoints
podService: true
# - NodePort
# - LoadBalancer
serviceType: NodePort
Key Configuration Details:
shardings
: Specifies a list of ShardingSpec objects that configure the sharding topology for components of a Cluster.Once the cluster is deployed, check its status:
kubectl get cluster redis-sharding -n demo -w
Expected Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
redis-sharding Delete Running 103s
Get all componets working for this cluster:
kubectl get cmp -l app.kubernetes.io/instance=redis-sharding -n demo
Expected Output:
NAME DEFINITION SERVICE-VERSION STATUS AGE
redis-sharding-shard-5cd redis-cluster-7-1.0.0 7.2.4 Running 2m34s
redis-sharding-shard-drg redis-cluster-7-1.0.0 7.2.4 Running 2m34s
redis-sharding-shard-tgf redis-cluster-7-1.0.0 7.2.4 Running 2m34s
Each component stands for a shard, with hash id as suffix.
Check pods and their roles
kubectl get pods -l app.kubernetes.io/instance=redis-sharding -L kubeblocks.io/role -n demo
Expected Output:
NAME READY STATUS RESTARTS AGE ROLE
redis-sharding-shard-5cd-0 2/2 Running 0 3m55s primary
redis-sharding-shard-5cd-1 2/2 Running 0 3m35s secondary
redis-sharding-shard-drg-0 2/2 Running 0 3m53s primary
redis-sharding-shard-drg-1 2/2 Running 0 3m35s secondary
redis-sharding-shard-tgf-0 2/2 Running 0 3m54s primary
redis-sharding-shard-tgf-1 2/2 Running 0 3m36s secondary
There are in-total six replicas in the cluster, two (one primarily and one secondary) for each component.
To remove all resources created during this tutorial:
kubectl delete cluster redis-sharding -n demo
kubectl delete ns demo