Backup and Restore Redis Cluster in Amazon Elastic Kubernetes Service (Amazon EKS) Using KubeDB


KubeDB is the Kubernetes Native Database Management Solution which simplifies and automates routine database tasks such as Provisioning, Monitoring, Upgrading, Patching, Scaling, Volume Expansion, Backup, Recovery, Failure detection, and Repair for various popular databases on private and public clouds. The databases that KubeDB supports are MySQL, MongoDB, MariaDB, Elasticsearch, Kafka, Redis, PostgreSQL, ProxySQL, Percona XtraDB, Memcached and PgBouncer. You can find the guides to all the supported databases in KubeDB . In this tutorial we will Backup and Restore Redis Cluster in Amazon Elastic Kubernetes Service (Amazon EKS). We will cover the following steps:

  1. Install KubeDB
  2. Deploy Redis Clustered Database
  3. Install Stash
  4. Backup Redis Cluster Using Stash
  5. Recover Redis Cluster Using Stash

Get Cluster ID

We need the cluster ID to get the KubeDB License. To get cluster ID, we can run the following command:

$ kubectl get ns kube-system -o jsonpath='{.metadata.uid}'

Get License

Go to Appscode License Server to get the license.txt file. For this tutorial we will use KubeDB Enterprise Edition.

License Server

Install KubeDB

We will use helm to install KubeDB. Please install helm here if it is not already installed. Now, let’s install KubeDB.

$ helm repo add appscode
$ helm repo update

$ helm search repo appscode/kubedb
NAME                              	CHART VERSION	APP VERSION	DESCRIPTION                                       
appscode/kubedb                   	v2023.04.10  	v2023.04.10	KubeDB by AppsCode - Production ready databases...
appscode/kubedb-autoscaler        	v0.18.0      	v0.18.1    	KubeDB Autoscaler by AppsCode - Autoscale KubeD...
appscode/kubedb-catalog           	v2023.04.10  	v2023.04.10	KubeDB Catalog by AppsCode - Catalog for databa...
appscode/kubedb-community         	v0.24.2      	v0.24.2    	KubeDB Community by AppsCode - Community featur...
appscode/kubedb-crds              	v2023.04.10  	v2023.04.10	KubeDB Custom Resource Definitions                
appscode/kubedb-dashboard         	v0.9.0       	v0.9.1     	KubeDB Dashboard by AppsCode                      
appscode/kubedb-enterprise        	v0.11.2      	v0.11.2    	KubeDB Enterprise by AppsCode - Enterprise feat...
appscode/kubedb-grafana-dashboards	v2023.04.10  	v2023.04.10	A Helm chart for kubedb-grafana-dashboards by A...
appscode/kubedb-metrics           	v2023.04.10  	v2023.04.10	KubeDB State Metrics                              
appscode/kubedb-one               	v2023.04.10  	v2023.04.10	KubeDB and Stash by AppsCode - Production ready...
appscode/kubedb-ops-manager       	v0.20.0      	v0.20.1    	KubeDB Ops Manager by AppsCode - Enterprise fea...
appscode/kubedb-opscenter         	v2023.04.10  	v2023.04.10	KubeDB Opscenter by AppsCode                      
appscode/kubedb-provisioner       	v0.33.0      	v0.33.1    	KubeDB Provisioner by AppsCode - Community feat...
appscode/kubedb-schema-manager    	v0.9.0       	v0.9.1     	KubeDB Schema Manager by AppsCode                 
appscode/kubedb-ui                	v2023.03.23  	0.3.28     	A Helm chart for Kubernetes                       
appscode/kubedb-ui-server         	v2021.12.21  	v2021.12.21	A Helm chart for kubedb-ui-server by AppsCode     
appscode/kubedb-webhook-server    	v0.9.0       	v0.9.1     	KubeDB Webhook Server by AppsCode 

# Install KubeDB Enterprise operator chart
$ helm install kubedb appscode/kubedb \
  --version v2023.04.10 \
  --namespace kubedb --create-namespace \
  --set kubedb-provisioner.enabled=true \
  --set kubedb-ops-manager.enabled=true \
  --set kubedb-autoscaler.enabled=true \
  --set kubedb-dashboard.enabled=true \
  --set kubedb-schema-manager.enabled=true \
  --set-file global.license=/path/to/the/license.txt

Let’s verify the installation:

$ watch kubectl get pods --all-namespaces -l ""
NAMESPACE   NAME                                            READY   STATUS    RESTARTS   AGE
kubedb      kubedb-kubedb-autoscaler-6c6997cdfd-szzdr       1/1     Running   0          2m
kubedb      kubedb-kubedb-dashboard-5675d74c5c-6bhj4        1/1     Running   0          2m
kubedb      kubedb-kubedb-ops-manager-68987fcc47-dqrvf      1/1     Running   0          2m
kubedb      kubedb-kubedb-provisioner-6b59db468d-kdzqw      1/1     Running   0          2m
kubedb      kubedb-kubedb-schema-manager-59689bf49d-ppthk   1/1     Running   0          2m
kubedb      kubedb-kubedb-webhook-server-75bf6cf447-rvt4s   1/1     Running   0          2m

We can list the CRD Groups that have been registered by the operator by running the following command:

$ kubectl get crd -l
NAME                                              CREATED AT   2023-05-09T08:13:18Z      2023-05-09T08:13:18Z                        2023-05-09T08:13:15Z           2023-05-09T08:13:15Z          2023-05-09T08:10:50Z                                  2023-05-09T08:13:22Z                   2023-05-09T08:10:51Z                                 2023-05-09T08:13:31Z                  2023-05-09T08:10:51Z         2023-05-09T08:13:18Z                2023-05-09T08:13:20Z                 2023-05-09T08:13:37Z                               2023-05-09T08:13:21Z                2023-05-09T08:10:51Z                             2023-05-09T08:13:23Z              2023-05-09T08:10:52Z         2023-05-09T08:13:18Z                2023-05-09T08:13:17Z                 2023-05-09T08:13:19Z                               2023-05-09T08:13:19Z                2023-05-09T08:10:52Z           2023-05-09T08:13:19Z                  2023-05-09T08:13:16Z                   2023-05-09T08:13:33Z                                 2023-05-09T08:13:17Z                  2023-05-09T08:10:52Z   2023-05-09T08:13:19Z           2023-05-09T08:13:50Z                         2023-05-09T08:13:29Z          2023-05-09T08:10:53Z                             2023-05-09T08:13:29Z              2023-05-09T08:10:53Z        2023-05-09T08:13:19Z               2023-05-09T08:13:19Z                             2023-05-09T08:13:20Z                2023-05-09T08:13:43Z               2023-05-09T08:10:53Z        2023-05-09T08:13:19Z                2023-05-09T08:13:47Z                              2023-05-09T08:13:30Z               2023-05-09T08:10:54Z                    2023-05-09T08:14:00Z           2023-05-09T08:13:20Z                                2023-05-09T08:13:30Z                   2023-05-09T08:13:40Z   2023-05-09T08:13:20Z           2023-05-09T08:13:53Z                         2023-05-09T08:13:31Z                  2023-05-09T08:10:54Z                   2023-05-09T08:14:03Z

Deploy Redis Clustered Database

Now we are going to Install Redis using KubeDB. First, let’s create a Namespace in which we will deploy the database.

$ kubectl create namespace demo
namespace/demo created

Here is the yaml of the Redis CRO we are going to use:

kind: Redis
  name: redis-cluster
  namespace: demo
  version: 7.0.10
  mode: Cluster
    master: 3
    replicas: 1 
  storageType: Durable
        storage: "1Gi"
    storageClassName: "gp2"
    - ReadWriteOnce
  terminationPolicy: WipeOut

Let’s save this yaml configuration into redis-cluster.yaml Then create the above Redis CRO

$ kubectl apply -f redis-cluster.yaml created

In this yaml,

  • spec.version field specifies the version of Redis. Here, we are using Redis version 7.0.10. You can list the KubeDB supported versions of Redis by running $ kubectl get redisversions command.
  • Another field to notice is the spec.storageType field. This can be Durable or Ephemeral depending on the requirements of the database to be persistent or not.
  • Lastly, the spec.terminationPolicy field is Wipeout means that the database will be deleted without restrictions. It can also be “Halt”, “Delete” and “DoNotTerminate”. Learn More about these HERE .

Once these are handled correctly and the Redis object is deployed, you will see that the following are created:

$ kubectl get all -n demo
NAME                         READY   STATUS    RESTARTS   AGE
pod/redis-cluster-shard0-0   1/1     Running   0          3m
pod/redis-cluster-shard0-1   1/1     Running   0          3m
pod/redis-cluster-shard1-0   1/1     Running   0          3m
pod/redis-cluster-shard1-1   1/1     Running   0          3m
pod/redis-cluster-shard2-0   1/1     Running   0          3m
pod/redis-cluster-shard2-1   1/1     Running   0          3m

NAME                         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/redis-cluster        ClusterIP   <none>        6379/TCP   4m
service/redis-cluster-pods   ClusterIP   None            <none>        6379/TCP   4m

NAME                                    READY   AGE
statefulset.apps/redis-cluster-shard0   2/2     4m
statefulset.apps/redis-cluster-shard1   2/2     4m
statefulset.apps/redis-cluster-shard2   2/2     4m

NAME                                               TYPE               VERSION   AGE   7.0.10    4m

NAME                             VERSION   STATUS   AGE   7.0.10    Ready    4m

Let’s check if the database is ready to use,

$ kubectl get redis -n demo
redis-cluster   7.0.10    Ready    4m

We have successfully deployed Redis in AWS. Now we can exec into the container to use the database.

Accessing Database Through CLI

To access the database through CLI, we have to get the credentials to access. Let’s export the credentials as environment variable to our current shell :

Export the Credentials

KubeDB will create Secret and Service for the database redis-cluster that we have deployed. Let’s check them by following command,

$ kubectl get secret -n demo
NAME                   TYPE                       DATA   AGE
redis-cluster-auth   2      5m
redis-cluster-config   Opaque                     1      5m

$ kubectl get service -n demo
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
redis-cluster        ClusterIP   <none>        6379/TCP   5m
redis-cluster-pods   ClusterIP   None            <none>        6379/TCP   5m

Now, we are going to use PASSWORD to authenticate and insert some sample data. First, let’s export the PASSWORD as environment variables to make further commands re-usable.

$ export PASSWORD=$(kubectl get secrets -n demo redis-cluster-auth -o jsonpath='{.data.\password}' | base64 -d)

Insert Sample Data

In this section, we are going to login into our Redis database pod and insert some sample data.

$ kubectl exec -it -n demo redis-cluster-shard0-0 -- redis-cli -c -a $PASSWORD> set Product1 KubeDB
-> Redirected to slot [15299] located at
OK> set Product2 Stash
-> Redirected to slot [2976] located at
OK> get Product1
-> Redirected to slot [15299] located at
"KubeDB"> get Product2
-> Redirected to slot [2976] located at
"Stash"> exit

We’ve successfully inserted some sample data to our database. More information about Run & Manage Redis on Kubernetes can be found in Redis Kubernetes.

Backup Redis Cluster Using Stash

Here, we are going to use Stash to backup the database we deployed before.

Install Stash

Kubedb Enterprise License works for Stash too. So, we will use the Enterprise license that we have already obtained.

$ helm install stash appscode/stash \
  --version v2023.04.30 \
  --namespace stash --create-namespace \
  --set features.enterprise=true \
  --set-file global.license=/path/to/the/license.txt

Let’s verify the installation:

$ kubectl get pods --all-namespaces -l
NAMESPACE   NAME                                      READY   STATUS    RESTARTS   AGE
stash       stash-stash-enterprise-7d497448b6-q4mhq   2/2     Running   0          2m

Now, to confirm CRD groups have been registered by the operator, run the following command:

$ kubectl get crd -l
NAME                                      CREATED AT          2023-05-09T09:13:34Z       2023-05-09T09:13:34Z   2023-05-09T09:13:33Z         2023-05-09T09:13:33Z              2023-05-09T09:11:48Z           2023-05-09T08:13:23Z         2023-05-09T09:13:35Z        2023-05-09T08:13:23Z                  2023-05-09T09:11:49Z

Prepare Backend

Stash supports various backends for storing data snapshots. It can be a cloud storage like GCS bucket, AWS S3, Azure Blob Storage etc. or a Kubernetes native resources like HostPath, PersistentVolumeClaim etc. or NFS.

For this tutorial we are going to use AWS S3 storage. You can find other setups in Stash Docs .

My Empty AWS storage

At first we need to create a secret so that we can access the AWS S3 storage bucket. We can do that by the following code:

$ echo -n 'changeit' > RESTIC_PASSWORD
$ echo -n '<your-aws-access-key-id-here>' > AWS_ACCESS_KEY_ID
$ echo -n '<your-aws-secret-access-key-here>' > AWS_SECRET_ACCESS_KEY
$ kubectl create secret generic -n demo s3-secret \
    --from-file=./RESTIC_PASSWORD \
    --from-file=./AWS_ACCESS_KEY_ID \
secret/s3-secret created

Create Repository

kind: Repository
  name: s3-repo
  namespace: demo
      bucket: stash-qa
      region: us-east-1
      prefix: /redis-cluster-backup
    storageSecretName: s3-secret

This repository CRO specifies the s3-secret we created before and stores the name and path to the AWS storage bucket. It also specifies the location to the container where we want to backup our database.

Here, My bucket name is stash-qa. Don’t forget to change spec.backend.s3.bucket to your bucket name and For S3, use as endpoint.

Lets create this repository,

$ kubectl apply -f s3-repo.yaml created

Create BackupConfiguration

Now, we need to create a BackupConfiguration file that specifies what to backup, where to backup and when to backup.

kind: BackupConfiguration
  name: redis-cluster-backup
  namespace: demo
  schedule: "*/5 * * * *"
    name: s3-repo
      kind: AppBinding
      name: redis-cluster
    name: keep-last-5
    keepLast: 5
    prune: true

Create this BackupConfiguration by following command,

$ kubectl apply -f redis-cluster-backup.yaml created
  • BackupConfiguration creates a cronjob that backs up the specified database ( every 5 minutes.
  • spec.repository contains the secret we created before called s3-secret.
  • contains the reference to the appbinding that we want to backup.
  • spec.schedule specifies that we want to backup the database at 5 minutes interval.
  • spec.retentionPolicy specifies the policy to follow for cleaning old snapshots.
  • To learn more about AppBinding, click here AppBinding . So, after 5 minutes we can see the following status:
$ kubectl get backupsession -n demo
NAME                              INVOKER-TYPE          INVOKER-NAME           PHASE       DURATION   AGE
redis-cluster-backup-1683624302   BackupConfiguration   redis-cluster-backup   Succeeded   15s        105s

$ kubectl get repository -n demo
s3-repo   true        471 B   1                2m17s                    4m12s

Now if we check our Amazon S3 bucket, we can see that the backup has been successful.


If you have reached here, CONGRATULATIONS!! 🎊 🎊 🎊 You have successfully backed up Redis Database using Stash. If you had any problem during the backup process, you can reach out to us via EMAIL .

Recover Redis Using Stash

Let’s think of a scenario in which the database has been accidentally deleted or there was an error in the database causing it to crash.

Temporarily pause backup

At first, let’s stop taking any further backup of the database so that no backup runs after we delete the sample data. We are going to pause the BackupConfiguration object. Stash will stop taking any further backup when the BackupConfiguration is paused.

$ kubectl patch backupconfiguration -n demo redis-cluster-backup --type="merge" --patch='{"spec": {"paused": true}}' patched

Now, we are going to delete those data to simulate accidental database deletion.

$ kubectl exec -it -n demo redis-cluster-shard0-0 -- redis-cli -c -a $PASSWORD> get Product1
-> Redirected to slot [15299] located at
"KubeDB"> get Product2
-> Redirected to slot [2976] located at
"Stash"> del Product1
-> Redirected to slot [15299] located at
(integer) 1> del Product2
-> Redirected to slot [2976] located at
(integer) 1> get Product1
-> Redirected to slot [15299] located at
(nil)> get Product2
-> Redirected to slot [2976] located at
(nil)> exit

Create a RestoreSession

Below, is the contents of YAML file of the RestoreSession object that we are going to create.

kind: RestoreSession
  name: redis-cluster-restore
  namespace: demo
    name: s3-repo
      kind: AppBinding
      name: redis-cluster
    - snapshots: [latest]

Now, let’s create RestoreSession that will initiate restoring from the cloud.

$ kubectl apply -f redis-cluster-restore.yaml created

This RestoreSession specifies where the data will be restored. Once this is applied, a RestoreSession will be created. Once it has succeeded, the database has been successfully recovered as you can see below:

$ kubectl get restoresession -n demo
NAME                    REPOSITORY   PHASE       DURATION   AGE
redis-cluster-restore   s3-repo      Succeeded   7s         51s

Now, let’s check whether the data has been correctly restored:

$ kubectl exec -it -n demo redis-cluster-shard0-0 -- redis-cli -c -a $PASSWORD> get Product1
-> Redirected to slot [15299] located at
"KubeDB"> get Product2
-> Redirected to slot [2976] located at
"Stash"> exit

You can see the data has been restored. The recovery of Redis cluster has been successful. If you faced any difficulties in the recovery process, you can reach out to us through EMAIL .

We have made an in depth video on how to Deploy Sharded Redis Cluster in Kubernetes Using KubeDB. You can have a look into the video below:


To speak with us, please leave a message on our website .

To receive product announcements, follow us on Twitter .

To watch tutorials of various Production-Grade Kubernetes Tools Subscribe our YouTube channel.

More about Redis in Kubernetes

If you have found a bug with KubeDB or want to request for new features, please file an issue .


Get Up and Running Quickly

Deploy, manage, upgrade Kubernetes on any cloud and automate deployment, scaling, and management of containerized applications.