Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Running Redis on Multi-Node Kubernetes Cluster in 5 Minutes

1 min read

Redis is a very popular open-source project with more than 47,200 GitHub stars, 18,700 forks, and 440+ contributors.  Stack Overflow’s annual Developer Survey has ranked Redis as the Most Loved Database platform for four years running! Redis fits very well into the DevOps model due to its ease of deployment, rigorous unit and functionality testing of core and supplementary Redis technology, and ease of automation through tools such as DockerAnsible, and Puppet.

In Datadog’s 2020 Container Report, Redis was the most-popular container image in Kubernetes StatefulSets. If you’re interested to test drive Redis over the multi-node Kubernetes cluster, this guide might be useful for you.


Ensure that Kubernetes(at least 2-node cluster) is installed in your system

Verify Kubernetes components:

$ kubectl get componentstatus
NAME                 STATUS    MESSAGE             ERROR
controller-manager   Healthy   ok
scheduler            Healthy   ok
etcd-0               Healthy   {"health":"true"}

Configuring Redis using a ConfigMap:

You can follow the steps below to configure a Redis cache using data stored in a ConfigMap.

[node1 kubelabs]$ curl -OL https://k8s.io/examples/pods/config/redis-config

First create a kustomization.yaml containing a ConfigMap from the redis-config file:

[node1 kubelabs]$ cat <<EOF >./kustomization.yaml
> configMapGenerator:
> - name: example-redis-config
>   files:
>   - redis-config

Add the pod resource config to the kustomization.yaml:

apiVersion: v1
kind: Pod
  name: redis
  - name: redis
    image: redis:5.0.4
      - redis-server
      - "/redis-master/redis.conf"
    - name: MASTER
      value: "true"
    - containerPort: 6379
        cpu: "0.1"
    - mountPath: /redis-master-data
      name: data
    - mountPath: /redis-master
      name: config
    - name: data
      emptyDir: {}
    - name: config
        name: example-redis-config
        - key: redis-config
          path: redis.conf

Apply the kustomization directory to create both the ConfigMap and Pod objects:

[node1 kubelabs]$ kubectl apply -k .
configmap/example-redis-config-dgh9dg555m created
pod/redis created

Examine the created objects by

kubectl get -k .
NAME                                        DATA   AGE
configmap/example-redis-config-dgh9dg555m   1      33s

pod/redis   1/1     Running   0          33s

In the example, the config volume is mounted at /redis-master. It uses path to add the redis-config key to a file named redis.conf. The file path for the redis config, therefore, is /redis-master/redis.conf. This is where the image will look for the config file for the redis master.
Use kubectl exec to enter the pod and run the redis-cli tool to verify that the configuration was correctly applied:

[node1 kubelabs]$ kubectl exec -it redis -- redis-cli> CONFIG GET maxmemory
1) "maxmemory"
2) "2097152"> CONFIG GET maxmemory-policy
1) "maxmemory-policy"
2) "allkeys-lru">

Delete the created pod:

$ kubectl delete pod redis
pod "redis" deleted

Further Reference:

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Leave a Reply

Your email address will not be published.

© Copyright Collabnix Inc

Built for Collabnix Community, by Community