• This repository has been archived on 18/Nov/2022
  • Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kubernetes Redis with High Availability

Kubernetes Redis with High Availability

Redis Images and Samples in this project are implemented using the latest features of Kubernetes:

  • StatefulSet
  • Init Container

Requirements

  • Kubernetes 1.6 cluster
  • Redis 3.2

Quick Start

If you already have a Kubernetes cluster, you can deploy High Availability Redis using the following command:

$ kubectl create -f example/
service "redis-sentinel" created
statefulset "redis-sentinel" created
service "redis-server" created
statefulset "redis-server" created
pod "console" created

Accessing Redis

You can access Redis server using console pod:

$ kubectl exec -ti console -- /bin/bash
root@console:# export MASTER_IP="$(redis-cli -h redis-sentinel -p 26379 sentinel get-master-addr-by-name mymaster | head -1)"
root@console:# export SERVER_PASS="_redis-server._tcp.redis-server.default.svc.cluster.local"
root@console:# redis-cli -h "${MASTER_IP}" -a "${SERVER_PASS}" set foo bar
OK
root@console:# redis-cli -h redis-server -a "${SERVER_PASS}" get foo
bar

The passowrd is necessary for preventing independent Redis clusters from merging together in some circumstances.

Scale Up and Down

With tarosky/k8s-redis-ha, you can scale up/down Redis servers and Redis sentinels like the normal Deployment resources:

$ kubectl scale --replicas=5 statefulset/redis-sentinel
statefulset "redis-sentinel" scaled
$ kubectl scale --replicas=5 statefulset/redis-server
statefulset "redis-server" scaled

After these scale up/down, the expected number of available slaves in the Redis set are reset automatically.

Sample Code in Python

$ kubectl exec -ti console -- ipython
In [1]: from redis import StrictRedis

In [2]: from redis.sentinel import Sentinel

In [3]: sentinel = Sentinel([
   ...:         ('redis-sentinel-0.redis-sentinel.default.svc.cluster.local', 26379),
   ...:         ('redis-sentinel-1.redis-sentinel.default.svc.cluster.local', 26379),
   ...:         ('redis-sentinel-2.redis-sentinel.default.svc.cluster.local', 26379)
   ...:     ], socket_timeout=0.1
   ...: )

In [4]: master = sentinel.master_for(
   ...:     'mymaster',
   ...:     password='_redis-server._tcp.redis-server.default.svc.cluster.local',
   ...:     socket_timeout=0.1
   ...: )

In [5]: slave = sentinel.slave_for(
   ...:     'mymaster',
   ...:     password='_redis-server._tcp.redis-server.default.svc.cluster.local',
   ...:     socket_timeout=0.1
   ...: )

In [6]: master.set('foo', 'bar')
Out[6]: True

In [7]: slave.get('foo')
Out[7]: b'bar'

Running the Test Script

$ pyvenv .venv
$ source .venv/bin/activate
$ pip install -r test/requirements.txt

You can run the test command using the following command:

$ KUBE_NAMESPACE='{{Your name space}}' nosetests test/test.py

More Repositories

1

logbook

A logging plugin for WordPress.
PHP
13
star
2

http2-server-push-preload

Send Link headers for HTTP/2 server push for WordPress
PHP
11
star
3

tscf

Tarosky's Custom Field Manager for WordPress. You will get smooth UI and maintenable custom fields.
PHP
8
star
4

redirect-for-contact-form-7

An add-on plugin for contact form 7 which redirects to the specific URL
PHP
7
star
5

k8s-mongo-ha

Kubernetes MongoDB with High Availability
Python
6
star
6

dig-srv

Self-executable DNS lookup command just for SRV records
Go
3
star
7

taro-sitemap

Yet another sitemap plugin for WordPress.
PHP
3
star
8

cookie-tasting

Detect user login only with cookie.
PHP
3
star
9

dig-a

Self-executable DNS lookup command just for A records
Go
3
star
10

wp-redis-patch

Subclass for WordPress redis-cache plugin.
PHP
2
star
11

rich-taxonomy

A WordPress plugin to enrich taxonomy archive.
PHP
2
star
12

customer-chat-for-facebook-messenger

A WordPress pluign which allows you to integrate customer chat for facebook messenger.
PHP
2
star
13

gutenberg-imgconv

Go
2
star
14

google-api-glob

A WordPress plugin to
PHP
2
star
15

membership

A PHP library for membership feature. Works with WooCommerce & Subscription.
PHP
2
star
16

paperboy

A WordPress plugin to deliver multiple news to news aggregators.
PHP
1
star
17

taro-video-collector

Collect videos and embed in your WordPress site via YouTube Data API.
PHP
1
star
18

gutenberg-parallelefs

Go
1
star
19

gutenberg-logfilter

Filter log files
Go
1
star
20

gutenberg-429

Go
1
star
21

reiwa

Convert the Christian era to Japanese imperial era "Eiwa". Also supports "Meiji", "Taisho", "Showa", and "Heisei".
1
star
22

gutenberg-notifier

Notify file changes on EFS for invalidating OPcache
C
1
star
23

taro-iframe-block

Iframe block for WordPress
JavaScript
1
star
24

taro-geo-taxonomy

WordPress plugin to create geometric taxonomy.
PHP
1
star
25

taro-open-hour

A WordPress plugin to display open hour.
PHP
1
star
26

gcbseq

Sequential build number generator for Google Cloud Build
Go
1
star
27

wp-dashboard

CSS framework for WordPress dashboard
1
star
28

michizure

CloudFormation template which deletes corresponding snapshot when an AMI is deregistered.
Python
1
star