hortonworks/k8s-redis-ha

Name: k8s-redis-ha

Owner: Hortonworks Inc

Description: Kubernetes Redis with High Availability

Forked from: keyki/k8s-redis-ha

Created: 2017-08-23 14:22:35.0

Updated: 2017-11-02 23:17:24.0

Pushed: 2018-01-08 13:58:11.0

Homepage: null

Size: 1770

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Kubernetes Redis with High Availability

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

Requirements

Quick Start

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

bectl create -f example/
ice "redis-sentinel" created
efulset "redis-sentinel" created
ice "redis-server" created
efulset "redis-server" created
"console" created
Accessing Redis

You can access Redis server using console pod:

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

@console:# redis-cli -h redis-server -a "${SERVER_PASS}" get foo

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:

bectl scale --replicas=5 statefulset/redis-sentinel
efulset "redis-sentinel" scaled
bectl scale --replicas=5 statefulset/redis-server
efulset "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

bectl exec -ti console -- ipython
ython
1]: from redis import StrictRedis

2]: from redis.sentinel import Sentinel

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
..: )

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

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

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

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

Running the Test Script

venv .venv
urce .venv/bin/activate
p install -r test/requirements.txt

You can run the test command using the following command:

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

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.