How to setup Redis on Kubernetes Cluster

8grams
4 min readApr 25, 2023

--

Redis

In the world of databases and data storage, Redis has gained significant popularity in recent years. This article will explore what Redis is, why it is so popular, its common use cases, and the differences between Redis cluster and standalone configurations.

About 8grams

We are a small DevOps Consulting Firm that has a mission to empower businesses with modern DevOps practices and technologies, enabling them to achieve digital transformation, improve efficiency, and drive growth.

Ready to transform your IT Operations and Software Development processes? Let’s join forces and create innovative solutions that drive your business forward.

Introduction

Redis, short for Remote Dictionary Server, is an open-source, in-memory data structure store that can be used as a database, cache, and message broker. It was created by Salvatore Sanfilippo in 2009 and has since become a widely adopted tool in the developer community. Due to its in-memory nature, Redis offers high performance and low latency, making it ideal for applications that require fast data processing and retrieval.

Why Redis?

In the world of databases and data storage, Redis has gained significant popularity in recent years. Redis has gained popularity for several reasons:

  1. Speed: Since Redis stores data in memory, it can provide significantly faster data access compared to traditional disk-based databases.
  2. Flexibility: Redis supports a wide range of data structures (such as strings, lists, sets, sorted sets, hashes, bitmaps, and hyperloglogs), making it suitable for various use cases.
  3. Scalability: Redis can be easily scaled horizontally and vertically to handle increasing workloads.
  4. Ease of use: Redis has an easy-to-understand and straightforward command syntax, which makes it a preferred choice for developers. Additionally, there are many client libraries available for various programming languages, making it simple to integrate Redis into existing applications.
  5. Active community: Redis has a vibrant and active community that contributes to its development, provides support, and shares knowledge, ensuring that the project continues to evolve and improve over time.

Use Cases

There are numerous use cases for Redis, but some of the most common ones include:

Caching
Redis is often used as a caching layer to store frequently accessed data, reducing the load on databases or other data sources and improving the overall performance of applications.

Session storage
Redis can be used to store session data for web applications, ensuring quick access to user information and a seamless browsing experience.

Message queuing
Redis can be used as a message broker to facilitate communication between different parts of an application, ensuring efficient and reliable data processing.

Real-time analytics
Redis's high performance makes it suitable for real-time analytics, such as tracking user activities, page views, or clickstreams.

Leaderboards and counting
Redis's sorted sets and increment/decrement operations make it ideal for implementing leaderboards, counters, and other similar functionality.

Redis in Kubernetes

In a Kubernetes environment, Redis cluster is often used to enhance the performance, scalability, and resilience of an application. Although Kubernetes does provide self-healing capabilities, there are still several advantages to using a Redis cluster within a Kubernetes environment:

  1. Horizontal scaling: A Redis cluster can be easily scaled horizontally by adding or removing nodes to handle increasing workloads. This is particularly important in a Kubernetes environment where applications can dynamically scale based on demand.
  2. Data sharding: Redis cluster distributes data across multiple nodes, which allows for better load balancing and improved performance. This is especially beneficial in a Kubernetes environment, where the distribution of data and processing loads is essential to ensure optimal performance.
  3. High availability: In a Redis cluster, data is replicated across multiple nodes, providing redundancy and fault tolerance. This means that if a node fails, the remaining nodes can continue to operate without data loss. While Kubernetes does provide self-healing capabilities, the use of a Redis cluster further enhances the system's resilience.
  4. Improved data persistence: Kubernetes can recover from failures and restart failed containers. However, using a Redis cluster can ensure that your data remains persistent and available even if a Redis instance fails within a Kubernetes environment.
  5. Easier management: Redis cluster can be managed using Kubernetes operators or Helm charts, making it easier to deploy, scale, and maintain within a Kubernetes environment. This allows for a more seamless and automated experience when managing the Redis cluster.

Setup Redis on Kubernetes Cluster

The recommended method for installing Redis on Kubernetes is by utilizing Helm charts, which provide a convenient and efficient way to manage and deploy applications. For the purpose of this article, we will focus on installing Redis in standalone mode, which is often sufficient for many use cases. However, we will delve into the installation process for a Redis cluster in a future article, catering to more complex scenarios that demand higher levels of scalability and fault tolerance.

Install Redis using Helm

Before proceeding with the installation of Redis on your Kubernetes cluster, it's important to ensure that Helm is installed and properly configured. Helm is a package manager for Kubernetes, which simplifies the deployment and management of applications on a cluster.

In this guide, we will be using the Redis Helm chart provided by Bitnami, as the Helm chart from the Helm stable repository has been deprecated. Bitnami is a well-known provider of open-source software stacks and maintains up-to-date, reliable Helm charts for various applications, including Redis.

Add Bitnami Helm Chart

~$ helm repo add bitnami https://charts.bitnami.com/bitnami

~$ helm repo update

Create a file named values.yml

This time, we will disable auth, but feel free to enable it in your own installation. The complete configuration can be seen on: https://github.com/bitnami/charts/tree/main/bitnami/redis.

Install Redis

~$ helm install redis bitnami/redis -f values.yaml

Verify Installation

~$ kubectl get statefulset
NAME READY AGE
redis-master 1/1 173d

Using Redis in Application

After Redis is installed successfuly, you can use it in your application, for Cache, Session, or Queue. Your Redis URI should look like

redis://redis-master.default

If you have auth enabled, then

redis://redis.default?password=<your password here>

--

--

8grams

We are a DevOps Consulting Firm with a mission to empower businesses with modern DevOps practices and technologies