Redis is a popular open-source in-memory datastore with a set of advanced features for high availability and data optimization.
For this demonstration, we leveraged Tanzu Kubernetes Grid 2.3.0 (Kubernetes 1.26.x) to create a well-configured and highly available infrastructure for our Redis deployment. The Tanzu Infrastructure played an important role in optimizing the deployment and management of Redis, adding further value to the backup and restore capabilities.
You can use a Helm chart to deploy a Redis cluster with sharding, and multiple write points on Kubernetes.
Once you deploy the Redis cluster on Kubernetes, it is essential to have a data backup strategy to protect the data within it. This backup strategy is required for many operational scenarios, such as, disaster recovery planning, off-site data analysis, or application load testing and so on.
This document explains the process to back up and restore a Redis Service on Tanzu Kubernetes Grid clusters using Velero, an open-source Kubernetes backup/restore tool.
kubectl
and Helm v3
CLI on the client machine.For this demonstration purpose, we use Helm to install Redis on the source cluster and upload some data to it.
redis
on source cluster for deploying the Redis Service.Deploy Redis using Helm by running the following command:
helm install redis oci://registry-1.docker.io/bitnamicharts/redis-cluster \
--namespace redis \
--set rootUser.password=VMware1!
Export the REDIS_PASSWORD
which is used to connect to the database:
export REDIS_PASSWORD=$(kubectl get secret --namespace "redis" redis-redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)
Deploy a Redis client pod that you can use as a client to connect to the database:
kubectl run --namespace redis redis-redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.2.3-debian-11-r1 -- bash
Connect to the database by using the Redis CLI:
redis-cli -c -h redis-redis-cluster -a $REDIS_PASSWORD
Upload data for testing purpose:
set foo 100
set bar 200
set foo1 300
set bar1 400
Validate the uploaded data:
get foo
get bar
get foo1
get bar1
In this section, we’ll use Velero to back up the Redis deployment including namespace.
Before backing up the data, use BGSAVE
command for creating backups in Redis. BGSAVE
creates a snapshot of the in-memory dataset and writes it to the disk.
NoteIf you have specific requirements for data consistency or if you want to create a point-in-time snapshot, you can use the
BGSAVE
command in Redis to trigger a background save operation before initiating the Velero backup. However, in many cases, the combination of Velero Filesystem backup is sufficient for routine backups without the need to stop the Redis database.
kubectl run --namespace redis redis-redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.2.3-debian-11-r1 -- bash
redis-cli -c -h redis-redis-cluster -a $REDIS_PASSWORD
BGSAVE
exit
Back up the Redis database by using velero:
# velero backup create redis-backup-05a --include-namespaces redis
Backup request "redis-backup-05a" submitted successfully.
Run `velero backup describe redis-backup-05a` or `velero backup logs redis-backup-05a` for more details.
Validate the backup status by running the following command:
# velero backup describe redis-backup-05a --details
We’ll now restore the Redis deployment on the destination cluster.
Run the following command to restore the backup:
# velero restore create --from-backup redis-backup-05a
Restore request "redis-backup-05a-20231220093241" submitted successfully.
Run `velero restore describe redis-backup-05a-20231220093241` or `velero restore logs redis-backup-05a-20231220093241` for more details.
Connect to the databse, and ensure that the data is intact:
kubectl run --namespace redis redis-redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.2.3-debian-11-r1 -- bash
redis-cli -c -h redis-redis-cluster -a $REDIS_PASSWORD
## validate the data
get foo
get bar
get foo1
get bar1
Regular backups of your Redis deployments are crucial for ensuring data safety and minimizing downtime. By using the procedures explained in this document, you can establish a reliable backup routine and test restoration practices to guarantee a swift and successful recovery when needed.