Geek Culture
Published in

Geek Culture

Redis Cluster on Kubernetes

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 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 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 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 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 of each Redis instance, you must have installed (see here).

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

selector:app: redis-cluster

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store