Redis Cluster on Kubernetes

Ferdinand de Antoni
Geek Culture

--

After setting up my Kubernetes cluster in my previous blog post, I decided to deploy a Redis cluster on it. It is surprisingly simple to do.

First we need to create a ConfigMap with the following:

This configuration will run Redis clustered and with persistence turned on using AOF (see Redis Persistence for more info).

Place the above content in a file called redis-config-map.yaml and create it on the cluster:

$ kubectl create -f redis-config-map.yaml

To run a Redis cluster on Kubernetes we will use a StatefulSet. Create a file called redis-sts.yaml with the following:

What will happen here is that on 6 nodes of the cluster we will run a Redis instance. These instances will each use a separate clustered block storage device to store their AOF.

Go ahead and create the stateful sets as follows:

$ kubectl create -f redis-sts.yaml

With the stateful sets now created, let’s define the service we need. Create a file called Redis-service.yaml with the following in it:

apiVersion: v1
kind: Service
metadata:
name: redis-cluster
namespace: redis
spec:
type: ClusterIP
ports:
- port: 6379
targetPort: 6379
name: client
- port: 16379
targetPort: 16379
name: gossip
selector:
app: redis-cluster

Create the service:

$ kubectl create -f redis-service.yaml

With the service created, we can now activate the Redis cluster:

Note that, to collect the ClusterIP of each Redis instance, you must have jq installed (see here).

Congratulations! You now have a Redis cluster up and running on your Kubernetes installation.

selector:app: redis-cluster

--

--