Deploying Redis on Alibaba Cloud Container Server for Kubernetes

This article details the deployment process for Redis to be deployed on Alibaba Cloud Container Service for Kubernetes using one single master node and multiple slave nodes.

Background: Understanding Kubernetes and Redis

Kubernetes and Alibaba Cloud Container Service for Kubernetes (ACK)

Kubernetes is an extensible open source platform for managing containerized workloads and services. By extension, Alibaba Cloud Container Service for Kubernetes (ACK) provides enterprise-level high-performance and flexible management of Kubernetes containerized applications. This service simplifies cluster creation and expansion and integrates Alibaba Cloud’s capabilities in virtualization, storage, network, and security, providing an improved running environment for Kubernetes containerized applications.

Redis and Its Related Architecture

Redis is an open source, in-memory data structure store that is designed to be fast and simple. Built for real-time performance, most requests to Redis complete in less than a millisecond, allowing a single server to handle millions of concurrent requests per second.

Whether used in single-instance or cluster mode, Redis can be set up for high availability. Redis Sentinel is a component that provides service discovery, failure detection and quorum-based failover from a primary to secondary replica for single-instance databases. When running Redis in cluster mode, these capabilities are provided by the cluster itself.

The Redis cluster enables horizontal scaling by automatically partitioning data across multiple Redis servers. The cluster provides near-linear scalability while growing across hundreds of nodes, and an interface that allows client applications to optimize access by discovering the cluster’s topology.

Redis utilizes a slave-master model in which the master node has a read/write capability while the slave nodes are read-only nodes. If the master node is down, then the sentinel conducts the election process among the slave nodes to select the new master node. Deploying on Container Engine allows us to identify pods as master and slave nodes within the cluster while utilizing the benefits and features of having routing and access managed by Alibaba Cloud.


Setting up for Redis to Be Deployed on ACK

1. Install and Configure Alibaba Cloud CLI

The first step is to install and configure Alibaba Cloud CLI.

Note: The Alibaba Cloud CLI is a tool to manage and use Alibaba Cloud resources through a command line interface. It is written in Go and built on the top of Alibaba Cloud OpenAPI.

First, use the brew to install Alibaba Cloud CLI. If you have installed brew in your Mac, you can use it to install Alibaba Cloud CLI as following:

Next, configure Alibaba Cloud CLI. To do this, run the aliyun configure command. An Alibaba Cloud account and a pair of AccessKey ID and AccessKey Secret are required for this action. You can get the AccessKey on the AccessKey page or get it from your system administrator.

A default profile is created with information provided which is in cn-hangzhou region in Simple Chinese language.

2. Create a Container Engine Cluster

To create a Container Engine cluster on which you’ll run the Redis service, create a container cluster named redis-cluster with 3 ecs.n1.small nodes in cn-hangzhou region. Change the VPC ID and VSwitch ID to the ID of the VPC and VSwtich you are using. Update the disk size and category to your use case.

3. Set up the Initial Master Node and Sentinel Pod

Set SSH to the master node by key pair followed by official help document:

The config file for the initial master and sentinel pod is redis-master.yaml.

Using official redis image in container registry with intranet for cost saving and best network performance.

4. Set up the Sentinel Service

Config for the sentinel service is sentinel-service.yaml.

5. Set up a Redis Replication Controller

The Config file for the redis replication controller is redis-controller.yaml.

6. Set up a Sentinel Replication Controller

Config for the sentinel replication controller: sentinel-controller.yaml.

7. Scale Redis and the Sentinel Pods

Now scale up both redis pods and sentinel pods to three replicas.

Verify redis master information

Testing the deployment

1. Delete the Redis Master Pod

Verify that the replication controller created a new pod.

Verify that an existing slave is elected to be the master.

Verify the status of the new pod.

2. Delete a Redis Slave Pod

Verify that the replication controller created a new pod.

Verify the status of the new pod.

3. Delete a Sentinel Pod

Verify the replication controller created a new sentinel pod.

Verify the status of redis master and slave pods and the sentinel service to confirm it remains the same.

4. Scale up the Redis Pods

Verify that the replication controller created new pods and their status.

5. Scale down the Redis Pods

Now scale up both redis pods 2 replicas.

Verify that pods were deleted and status of existing pods.


By Bo Yang, Alibaba Cloud Community Blog author.

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

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