Operations
Backup And Restores
Custom Secret
Monitoring
tpl
This guide demonstrates how to configure a Redis cluster on KubeBlocks with:
This combination provides comprehensive data protection with minimal recovery point objectives (RPO).
Point-In-Time Recovery (PITR) allows you to restore a database to a specific moment in time by combining full backups with continuous binlog/wal/archive log backups.
For details on restoring data from both full backups and continuous binlog backups, refer to the Restore From PITR guide.
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
Backup Repository Configured:
BackupRepo
BackupRepo
status is Ready
Cluster is Running:
Running
stateKubeBlocks Redis supports these backup methods:
Feature | Method | Description |
---|---|---|
Full Backup | datafile | Uses redis-cli BGSAVE command to backup data |
Continuous Backup | aof | Continuously perform incremental backups by archiving Append-Only Files (AOF) |
KubeBlocks uses a declarative approach for managing Redis Replication Clusters. Below is an example configuration for deploying a Redis Replication Cluster with two components, redis and redis sentinel.
Apply the following YAML configuration to deploy the cluster:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: redis-replication
namespace: demo
spec:
terminationPolicy: Delete
clusterDef: redis
topology: replication
componentSpecs:
- name: redis
serviceVersion: "7.2.4"
disableExporter: false
replicas: 2
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: redis-sentinel
replicas: 3
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
Monitor the cluster status until it transitions to the Running state:
kubectl get cluster redis-replication -n demo -w
Expected Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
redis-replication redis Delete Running 3m49s
Check the pod status and roles:
kubectl get pods -l app.kubernetes.io/instance=redis-replication -L kubeblocks.io/role -n demo
Expected Output:
NAME READY STATUS RESTARTS AGE ROLE
redis-replication-redis-0 3/3 Running 0 3m38s primary
redis-replication-redis-1 3/3 Running 0 3m16s secondary
redis-replication-redis-sentinel-0 2/2 Running 0 4m35s
redis-replication-redis-sentinel-1 2/2 Running 0 4m17s
redis-replication-redis-sentinel-2 2/2 Running 0 3m59s
Once the cluster status becomes Running, your Redis cluster is ready for use.
If you are creating the cluster for the very first time, it may take some time to pull images before running.
aof-timestamp-enabled
to yes
Redis Append Only Files(AOFs) record every write operation received by the server, in the order they were processed, which allows Redis to reconstruct the dataset by replaying these commands.
KubeBlocks supports continuous backup for the Redis component by archiving Append-Only Files (AOF). It will process incremental AOF files, update base AOF file, purge expired files and save backup status (records metadata about the backup process, such as total size and timestamps, to the Backup
resource).
Before enabling a continuous backup, you must set variable aof-timestamp-enabled
to yes
.
# cat examples/redis/reconfigure-aof.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: redis-reconfigure-aof
namespace: demo
spec:
clusterName: redis-replication
reconfigures:
- componentName: redis
parameters:
# Represents the name of the parameter that is to be updated.
- key: aof-timestamp-enabled
value: 'yes'
type: Reconfiguring
Once aof-timestamp-enabled
is on, Redis will include timestamp in the AOF file.
It may have following side effects: storage overhead, performance overhead (write latency).
It is not recommended to enable this feature when you have high write throughput, or you have limited storage space.
Update BackupSchedule
to schedule enable(enabled
) backup methods and set the time (cronExpression
) to your need:
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: BackupSchedule
spec:
backupPolicyName: redis-replication-redis-backup-policy
schedules:
- backupMethod: datafile
# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── day of week (0-6) (Sunday=0)
# │ │ │ │ │
# 0 18 * * *
# schedule this job every day at 6:00 PM (18:00).
cronExpression: 0 18 * * * # update the cronExpression to your need
enabled: true # set to `true` to schedule base backup periodically
retentionPeriod: 7d # set the retention period to your need
- backupMethod: aof
cronExpression: '*/30 * * * *'
enabled: true # set to `true` to enable continuous backup
name: aof
retentionPeriod: 8d # by default, retentionPeriod of continuous backup is 1d more than that of a full backup.
BGSAVE
command to perform a full backupVerify continuous backup operation with these commands:
# get continuous backup
kubectl get backup -l app.kubernetes.io/instance=redis-replication,dataprotection.kubeblocks.io/backup-type=Continuous -n demo
# get pod working for continuous backup
kubectl get pod -l app.kubernetes.io/instance=redis-replication,dataprotection.kubeblocks.io/backup-type=Continuous -n demo
This guide covered:
Key Benefits: