Operations
Backup And Restores
Custom Secret
Monitoring
tpl
Create a Full Backup for Redis on KubeBlocks
This guide demonstrates how to create and validate full backups for Redis clusters on KubeBlocks using the pg-basebackup
method through both:
- The Backup API (direct backup operations)
- The OpsRequest API (managed backup operations with enhanced monitoring)
We will cover how to restore data from a backup in the Restore From Full Backup guide.
Prerequisites
Before proceeding, ensure the following:
- Environment Setup:
- A Kubernetes cluster is up and running.
- The kubectl CLI tool is configured to communicate with your cluster.
- KubeBlocks CLI and KubeBlocks Operator are installed. Follow the installation instructions here.
- Namespace Preparation: To keep resources isolated, create a dedicated namespace for this tutorial:
kubectl create ns demo
namespace/demo created
Deploy a Redis Cluster
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
Verifying the Deployment
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.
Backup Prerequisites
Before creating backups, ensure:
-
Backup repository is configured:
BackupRepo
resource exists- Network connectivity between cluster and repository
BackupRepo
status shows "Ready"
-
Cluster is ready:
- Cluster status is "Running"
- No ongoing operations (scaling, upgrades, etc.)
Identify Backup Configuration
Check available backup policies and schedules:
# List backup policies
kubectl get backuppolicy -n demo -l app.kubernetes.io/instance=redis-replication
# List backup schedules
kubectl get backupschedule -n demo -l app.kubernetes.io/instance=redis-replication
Expected Output:
NAME BACKUP-REPO STATUS AGE
redis-replication-redis-backup-policy Available 17m
NAME STATUS AGE
redis-replication-redis-backup-schedule Available 60m
View supported backup methods in the BackupPolicy CR 'redis-replication-redis-backup-policy':
kubectl get backuppolicy redis-replication-redis-backup-policy -n demo -oyaml | yq '.spec.backupMethods[].name'
List of Backup methods
KubeBlocks 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) |
Backup via Backup API
1. Create On-Demand Backup
The datafile
method uses redis BGSAVE
command to perform a full backup and upload backup file using datasafed push
.
Apply this manifest to create a backup:
apiVersion: dataprotection.kubeblocks.io/v1alpha1
kind: Backup
metadata:
name: redis-backup-datafile
namespace: demo
spec:
backupMethod: datafile
backupPolicyName: redis-replication-redis-backup-policy
# Determines whether the backup contents stored in the backup repository should be deleted
# when the backup custom resource(CR) is deleted. Supported values are `Retain` and `Delete`.
# - `Retain` means that the backup content and its physical snapshot on backup repository are kept.
# - `Delete` means that the backup content and its physical snapshot on backup repository are deleted.
deletionPolicy: Delete
2. Monitor Backup and Verify Completion
Track progress until status shows "Completed":
kubectl get backup redis-backup-datafile -n demo -w
Example Output:
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION DELETION-POLICY CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
redis-backup-datafile redis-replication-redis-backup-policy datafile <BACKUP_REPO> Completed 3412 10s Delete 2025-05-17T09:24:59Z 2025-05-17T09:25:08Z
3. Validate Backup
Confirm successful completion by checking:
- Backup status shows "Completed"
- Backup size matches expectations
- Check files in the BackupRepo
The Backup
resource records details including:
- Storage path
- Time range
- Backup file size
Backup via OpsRequest API
1. Create On-Demand Backup
Execute a backup using the OpsRequest API with the 'pg-basebackup' method:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: redis-replication-backup
namespace: demo
spec:
clusterName: redis-replication
force: false
backup:
backupPolicyName: redis-replication-redis-backup-policy
backupMethod: datafile
deletionPolicy: Delete
retentionPeriod: 1mo
type: Backup
2. Monitor Backup Progress
1. Monitor Operation Status
Track backup progress in real-time:
kubectl get ops redis-replication-backup -n demo -w
Expected Output:
NAME TYPE CLUSTER STATUS PROGRESS AGE
redis-replication-backup Backup redis-replication Succeed -/- 35s
- A STATUS of 'Succeed' indicates the backup operation completed successfully.
2. Verify Completion
Check the final backup status:
kubectl get backup -n demo -l operations.kubeblocks.io/ops-name=redis-replication-backup
Example Output:
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION DELETION-POLICY CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
backup-demo-redis-replication-20250517092706 redis-replication-redis-backup-policy datafile <BACKUP_REPO> Completed 3458 10s Delete 2025-05-17T09:27:06Z 2025-05-17T09:27:16Z 2025-06-16T09:27:16Z
- The backup status should show 'Completed'.
3. Validate Backup
Confirm successful completion by checking:
- Backup status shows "Completed"
- Backup size matches expectations
- Files in the BackupRepo
The Backup
resource records details including:
- Storage path
- Time range
- Other metadata
Summary
This guide covered:
- Deploying a replication Redis cluster
- Creating full backups using:
- Direct Backup API
- Managed OpsRequest API
- Monitoring and validating backups
Your Redis data is now securely backed up and ready for restoration when needed.