fbpx
How to Deploy Redis on Kubernetes

This article provides a detailed guide on how to install Redis on Kubernetes, covering everything from configuring the Kubernetes environment to installing and administering Redis. The demand for effective, scalable, and trustworthy data storage solutions has increased as the world transitions to microservices and containerized applications. Redis, a high-performance in-memory data structure store popularly used for caching, session management, and real-time analytics, is one such solution. Redis’ scalability and dependability can be greatly improved by deploying it on Kubernetes, an open-source platform for managing containerized workloads.

Before we dive into the installation of K3s, it’s crucial to prepare your Ubuntu 22.04 server. Your server should meet the following minimum requirements:

  • 2 GB RAM
  • 2 CPUs
  • 40 GB of Disk Space
  • Ubuntu 22.04 LTS installed. You can buy a powerful Ubuntu VPS from Virtono (29 locations).

Step 1: Preparing the Server

We must first configure the server where the Kubernetes cluster will run before we can deploy Redis on it. The steps are the same for other operating systems, but for the purposes of this guide, we’ll assume you’re using a server that is based on Linux.

First, update and upgrade your server’s package index:

apt-get update && apt-get upgrade -y

These commands will install the most recent versions of all packages already present on your system and update the package lists to reflect upgrades and new package installations. Updating your system is beneficial because it makes sure you have the newest features and security patches.

Step 2: Installing K3s

Use the installation script offered by Rancher to install K3s. The script adds a systemd service that keeps K3s running and downloads the K3s binary. Additionally, it generates a kubeconfig file so that the user can communicate with the K3s cluster.

curl -sfL https://get.k3s.io | sh -
How to Deploy Redis on Kubernetes

To verify the installation, use:

sudo k3s kubectl get node

If K3s is installed correctly, you should see the name of your server in the output.

Redis on Kubernetes

Copy the K3s kubeconfig file to your home directory:

sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config

Check Cluster Connectivity:

Use kubectl to check if your cluster is reachable and working correctly:

kubectl cluster-info
Check Cluster Connectivity

Step 3: Deploying Redis on Kubernetes

After K3s has been configured, Redis should be deployed. In order to deploy Redis on Kubernetes cluster, we will use a Helm chart. Helm is a Kubernetes package manager that makes it easier to deploy applications.

# curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
# sudo apt-get install apt-transport-https --yes
# echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
# sudo apt-get update
# sudo apt-get install helm

Next, add the Bitnami repository, which contains the Redis chart:

# helm repo add bitnami https://charts.bitnami.com/bitnami
# helm repo update
Deploy Redis on Kubernetes

Create Redis namespace

sudo kubectl create namespace redis

Now, deploy Redis on Kubernetes using the Helm chart:

helm install my-release bitnami/redis --namespace redis

This command deploys Redis on Kubernetes with a set of configurations that are suitable for production environments. 

deploy Redis using the Helm chart

Step 4: Verifying the Deployment

Use the following kubectl command to see if Redis on Kubernetes is active:

kubectl get pods -n redis
NAME                          READY   STATUS    RESTARTS   AGE
my-release-redis-master-0     1/1     Running   0          9m20s
my-release-redis-replicas-0   1/1     Running   0          9m20s
my-release-redis-replicas-1   1/1     Running   0          8m43s
my-release-redis-replicas-2   1/1     Running   0          8m19s

If Redis on Kubernetes is running correctly, you should see a pod with a Running status.

Step 5: Connecting to Redis

To connect to Redis, you can use the redis-cli tool. First, you need to install it:

sudo apt install redis-tools

Then, you can connect to Redis:

kubectl exec -it my-release-redis-master-0 -n redis -- redis-cli
Connecting to Redis

Final Thoughts

The specific steps needed to deploy Redis on K3s on an Ubuntu 22.04 server were covered in detail in this article. Redis-like applications are simple to deploy and Kubernetes management is made simple with the aid of K3s. This set up can be used in a variety of circumstances, including environments for development, testing, and even production. Always keep in mind that the configurations used in this guide are basic and may require adjusting for a production setup.


2 Comments

How To Deploy PostgreSQL On K3s - Virtono Community · July 26, 2023 at 10:43 AM

[…] K3s should already be installed and running on your machine. You can learn How to install K3s here. […]

How To Deploy Postgres High Availability On Kubernetes - Virtono Community · July 28, 2023 at 10:55 AM

[…] A Running K3s Cluster: A functioning K3s cluster is a must. If you don’t have one, follow our K3s installation guide. […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.