How to Deploy Redis on OpenShift Easily using HELM

Red Hat OpenShift is a popular enterprise Kubernetes application platform. Openshift has been traditionally considered a platform for stateless applications. However, many developers are exploring the possibility of running stateful workloads, such as Redis, on OpenShift. If you are considering extending OpenShift for stateful workloads, this tutorial will help you experiment in your existing OpenShift environment with step-by-step instructions on how to deploy Redis on OpenShift.

Deploy Redis on OpenShift Using Helm

In this tutorial, we will deploy Redis on OpenShift using Helm with a single command, load data in the database, and register the Helm release as an application with ROBIN Storage.

Before you begin this tutorial, install ROBIN Storage on your existing OpenShift cluster.

After you have installed ROBIN, let us run a few commands to make sure the status of  all nodes are in the expected state. The nodes should be in “ready” state.

Let us now confirm that OpenShift cluster is up and running.

 
 
oc get nodes
 
 
 

You should see an output similar to below, with the list of nodes and their status as “Ready”.

Let us confirm that ROBIN is up and running. Run the following command to verify that ROBIN Storage is ready.

 
 
oc get robincluster -n robinio
 
 

Setting up HELM

Let us now set up helm. ROBIN has helper utilities to initialize helm.

 
 
robin k8s deploy-tiller-objects
 
robin k8s helm-setup
 
helm repo add stable https://kubernetes-charts.storage.googleapis.com
 
 
 

Project setup for tutorial

Lets create a new project for this tutorial. Add the policy as follows.

 
 
oc new-project redis-tutorial oc adm policy add-scc-to-user anyuid system:serviceaccount:redis-tutorial:default
 
 

Let us now create a Redis cluster using Helm and ROBIN Storage. Run the following command to install Redis. We are setting the storageClass to robin-0-3 to benefit from the data management capabilities that ROBIN Storage brings.

 
 
helm install stable/redis --name employees --set master.persistence.storageClass=robin-0-3 --set slave.persistence.storageClass=robin-0-3 --set master.service.type=LoadBalancer --namespace redis-tutorial
 
 
 

Let’s confirm that redis is deployed and all relevant Kubernetes resources are ready.
You should be able to see an output showing the status of your redis store.

Get the service IP address of our Redis store.

 
 
export REDIS_PASSWORD=$(oc get secret --namespace redis-tutorial employees-redis -o jsonpath="{.data.redis-password}" | base64 --decode)
 
 
 

Get the password of the redis store from Kubernetes secret.

 
 
export SERVICE_IP=$(oc get svc --namespace redis-tutorial employees-redis-master --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
 
 
 

Create a Redis client pod

Run a Redis pod that can be used as a Redis client. This will be used to connect to redis store and add data.

 
 
oc run --namespace default employees-redis-client --rm --tty -i --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --env SERVICE_IP=$SERVICE_IP --image docker.io/bitnami/redis:5.0.5-debian-9-r14 -- bash
 
 
 

From this point in the document, “redis-cli” invocations are always in the “employees-redis-client” pod.

Adding data to the Redis store

We will insert employee entries into redis store. Lets use the redis-cli from the redis client pod.

 
 
redis-cli -h $SERVICE_IP -a $REDIS_PASSWORD
 
hmset employees e000001 'Carmina Chilcote' e000002 'Werner Whobrey' e000003 'Jenna Jarmon' e000004 'Norbert Niswonger' e000004 'Randell Reimers' e000005 'Janay Jacobi' e000006 'Tammara Theobald' e000007 'Margret Michelin' e000008 'Daron Desrosier' e000009 'Raymon Riggenbach'
 
 
 

Lets run the following command to verify that the records are added.

 
 
redis-cli -h $SERVICE_IP -a $REDIS_PASSWORD hvals employees
 
 

We now have a Redis database deployed on OpenShift with some sample data. Now, let’s take a look at the data management capabilities ROBIN brings, such as taking snapshots, making clones, and creating backups.

Registering the Redis Helm release as an application

To benefit from the data management capabilities, we’ll register our Redis database with ROBIN. Doing so will let ROBIN map and track all resources associated with the Helm release for this Redis database.

Let us first get the ‘robin’ client utility and set it up to work with this OpenShift cluster.

To get the link to download robin client run the following command:

 
 
robin app register empapp --app helm/employees -n redis-tutorial
 
 
 

Let us now verify ROBIN is now tracking our Redis Helm release as a single entity (app).
You should see an output similar to the following.

Let us now verify that ROBIN is tracking our Redis Helm release as a single entity (app).

 
 
robin app status --app empapp
 
 
 

We have successfully registered our Helm release as an app called “empapp”.

This concludes the Deploy Redis on OpenShift tutorial. Now that we have deployed the Redis database, loaded data, and registered the Redis Helm release with ROBIN, we can create a Redis database snapshot and create a Redis clone including app plus data.

Recommended Posts