KubeBlocks
BlogsKubeBlocks Cloud
Overview
Quickstart

Topologies

Redis Standalone Cluster
Redis Replication Cluster
Redis Sharding Cluster

Operations

Lifecycle Management
Vertical Scaling
Horizontal Scaling
Volume Expansion
Manage Redis Services
Modify Redis Parameters
Redis Switchover
Decommission Redis Replica

Backup And Restores

Create BackupRepo
Create Full Backup
Scheduled Backups
Scheduled Continuous Backup
Restore Redis Cluster
Restore with PITR

Custom Secret

Custom Password

Monitoring

Observability for Redis Clusters

tpl

  1. Prerequisites
  2. Deploy a Redis Cluster
  3. Verifying the Deployment
  4. Prerequisites for Backup
  5. Configure Scheduled Backups
  6. Monitoring and Managing Backups
  7. Cleanup
  8. Summary

Setting Up a Redis Cluster with Scheduled Backups in KubeBlocks

This guide demonstrates how to deploy a Redis cluster using KubeBlocks and configure scheduled backups with retention in an S3 repository.

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.

        TIP

        If you are creating the cluster for the very first time, it may take some time to pull images before running.

        Prerequisites for Backup

        1. Backup Repository Configured:

          • Configured BackupRepo
          • Network connectivity between cluster and repo, BackupRepo status is Ready
        2. Cluster is Running:

          • Cluster must be in Running state
          • No ongoing operations (scaling, upgrades etc.)

        Configure Scheduled Backups

        KubeBlocks automatically creates a BackupSchedule resource when the cluster is created. Follow these steps to enable and configure scheduled backups:

        1. Verify the default backup schedule configuration:
        kubectl get backupschedule redis-replication-redis-backup-schedule  -n demo -oyaml
        

        Example Output:

        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: false # set to `true` to schedule base backup periodically
            retentionPeriod: 7d # set the retention period to your need
        
        1. Enable and customize the backup schedule:
        kubectl edit backupschedule redis-replication-redis-backup-schedule -n demo
        

        Update these key parameters:

        • enabled: Set to true to activate scheduled backups
        • cronExpression: Configure backup frequency using cron syntax
        • retentionPeriod: Set how long to keep backups (e.g., 7d, 1mo)

        Example configuration for daily backups at 6PM UTC with 7-day retention:

        schedules:
        - backupMethod: datafile
          enabled: true
          cronExpression: "0 18 * * *"
          retentionPeriod: 7d
        
        1. Verify the schedule configuration:
        # Check schedule status
        kubectl get backupschedule redis-replication-redis-backup-schedule -n demo -w
        
        # View detailed configuration
        kubectl describe backupschedule redis-replication-redis-backup-schedule -n demo
        

        Monitoring and Managing Backups

        After enabling scheduled backups, monitor their execution and manage backup retention:

        1. View all backups:
        kubectl get backup -n demo -l app.kubernetes.io/instance=redis-replication
        
        1. Inspect backup details:
        kubectl describe backup <backup-name> -n demo
        
        1. Verify backup artifacts:
        • Status should show "Completed"
        • Check backup size matches expectations
        • Confirm retention period is being applied
        • Validate backup files exist in repository
        1. Manage backup retention:
        • To manually delete old backups:
        kubectl delete backup <backup-name> -n demo
        
        • To modify retention period:
        kubectl edit backupschedule redis-replication-redis-backup-schedule -n demo
        

        Cleanup

        To remove all created resources, delete the Redis cluster along with its namespace:

        kubectl delete cluster redis-replication -n demo
        kubectl delete ns demo
        

        Summary

        This guide demonstrated:

        1. Configuration of automated Redis backups
        2. Schedule customization using cron syntax
        3. Retention policy management
        4. Backup verification procedures

        Your Redis cluster now has:

        • Regular automated backups
        • Configurable retention policies
        • Complete backup history tracking

        © 2025 ApeCloud PTE. Ltd.