Tutorial - Deploy Redis Guestbook Microservice App on Kubernetes

In this tutorial, we are going to expand our examples by deploying a more complex microservice. The idea is to make you more comfortable with the platform and to show you how you can leverage it for more advanced scenarios.

In this example, we are going to see the deployment of:

  • A Redis master
  • Multiple Redis slaves
  • A sample guestbook application that uses Redis as a store

We assume that you have already set up a Platform9 cluster with at least one node, and the cluster is ready.

Let’s start with the Redis parts.

Deploying and exposing a Redis Cluster

Redis is a key-value in-memory store that is used mainly as a cache service. To set up Clustering for Data Replication, we need a Redis instance that acts as Master , together with additional instances as slaves. Then the guestbook application can use this instance to store data. The Redis master will propagate the writes to the slave nodes.

We can initiate a Redis Master deployment in a few different ways: either using the kubectl tool, the Platform9 UI or the Kubernetes UI. For convenience, we use the kubectl tool as it’s the most commonly understood in tutorials.

First, we need to create a Redis Cluster Deployment. Looking at their documentation here, to set up a cluster, we need some configuration properties. We can leverage kubernetes configmaps to store and reference them in the deployment spec.

We need to save a script and a redis.conf file that is going to be used to configure the master and slave nodes.

Create redis-cluster.config.yml file with the following configuration:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-cluster-config
data:
  update-ip.sh: |
    #!/bin/sh
    sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${IP}/" /data/nodes.conf
    exec "$@"
  redis.conf: |+
    cluster-enabled yes
    cluster-config-file /data/nodes.conf
    appendonly yes

We define a script that will insert an IP value to the node.conf file. This is to fix an issue with Redis as referenced here. We use this script every time we deploy a new Redis image.

Then, we have the redis.conf , which applies the minimal cluster configuration.

Apply this spec into the cluster:

$ kubectl apply -f redis-cluster.config.yml

View the tutorial at https://docs.platform9.com/kubernetes/tutorials/deploy-redis-microservices-app/