Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from CommercialTribe/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jwaldrip committed Feb 21, 2017
2 parents a25961e + afb6857 commit 30ee361
Show file tree
Hide file tree
Showing 17 changed files with 307 additions and 215 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ deploy:
on:
branch: master
- provider: script
script: ./deploy.sh develop gke_commercial-tribe_us-east1-c_staging development
script: ./deploy.sh develop gke_commercial-tribe_us-east1-c_staging
on:
branch: develop
- provider: script
script: ./deploy.sh staging gke_commercial-tribe_us-east1-c_staging production
script: ./deploy.sh staging gke_commercial-tribe_us-east1-c_staging
on:
branch: master
- provider: script
script: ./deploy.sh production gke_commercial-tribe_us-east1-c_production production
script: ./deploy.sh production gke_commercial-tribe_us-east1-c_production
on:
tags: true
condition: $TRAVIS_TAG =~ ^v20.*$
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
FROM ruby:2.4
FROM redis:3.2
MAINTAINER Jason Waldrip <jwaldrip@commercialtribe.com>

RUN gem install redis
ADD http://download.redis.io/redis-stable/src/redis-trib.rb /usr/local/bin/redis-trib
RUN chmod +x /usr/local/bin/redis-trib
ADD https://storage.googleapis.com/kubernetes-release/release/v1.5.3/bin/linux/amd64/kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl

WORKDIR app
ADD runner.sh ./runner.sh
RUN chmod +x ./runner.sh
CMD ./runner.sh
WORKDIR /app
ADD sidecar.sh /app/sidecar.sh
RUN chmod +x /app/sidecar.sh
CMD /app/sidecar.sh
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 CommercialTribe, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# kube-redis
Resources for running Redis on Kubernetes
# Redis on Kubernetes as StatefulSet

The following document describes the deployment of a self-bootstrapping, reliable,
multi-node Redis on Kubernetes. It deploys a master with replicated slaves, as
well as replicated redis sentinels which are use for health checking and failover.

## Prerequisites

This example assumes that you have a Kubernetes cluster installed and running,
and that you have installed the kubectl command line tool somewhere in your path.
Please see the getting started for installation instructions for your platform.

### Storage Class

This makes use of a StorageClass, either create a storage class with the name of
"ssd" or update the StatefulSet to point to to the correct StorageClass.

## Running

To get your cluster up and running simple run:

`kubectl apply -Rf k8s`

The cluster will automatically bootstrap itself.

### Caveats

Your pods may not show up in the dashboard. This is because we automatically add
additional labels to the pods to recognize the master. To see the pods within the
dashboard you should look at the redis-nodes service instead.
19 changes: 15 additions & 4 deletions build-and-push.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/usr/bin/env bash
image=commercialtribe/redis-sidecar
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker build -t $image .
docker push $image
image="commercialtribe/redis-sentinel-sidecar"

login(){
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
}

push(){
docker push $image
}

build() {
docker build -t $image .
}

build && (push || (login && push))
3 changes: 1 addition & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/usr/bin/env bash
kubectl --namespace="$1" --context="$2" apply -Rf=./k8s/shared
kubectl --namespace="$1" --context="$2" apply -Rf=./k8s/$3
kubectl --namespace="$1" --context="$2" ${ACTION-"apply"} -Rf=./k8s
7 changes: 0 additions & 7 deletions k8s/development/redis-config-map.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions k8s/production/redis-config-map.yaml

This file was deleted.

13 changes: 13 additions & 0 deletions k8s/redis-config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-sentinel
data:
# Use the following file for reference http://download.redis.io/redis-stable/redis.conf
node.conf: |
protected-mode no
port 6379
tcp-backlog 511
loglevel notice
logfile ""
dir /data
13 changes: 13 additions & 0 deletions k8s/redis-master-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
service: redis
spec:
ports:
- port: 6379
name: redis
selector:
name: redis-sentinel-node
role: master
86 changes: 86 additions & 0 deletions k8s/redis-node-statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: redis
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
serviceName: redis-nodes
replicas: 3
template:
metadata:
labels:
name: redis-node
spec:
terminationGracePeriodSeconds: 10
containers:
# Redis
- name: redis
image: redis:3.2
command:
- redis-server
args:
- /config/node.conf
ports:
- name: redis
containerPort: 6379
volumeMounts:
- name: data
mountPath: /data
- name: redis-config
mountPath: /config
livenessProbe: &healthcheck
exec:
command: [ "redis-cli", "ping" ]
readinessProbe:
<<: *healthcheck

# Sentinel
- name: sentinel
image: redis:3.2
command: [ "bash", "-c", "touch sentinel.conf && redis-sentinel sentinel.conf" ]
ports:
- name: sentinel
containerPort: 26379
livenessProbe: &healthcheck
exec:
command: [ "redis-cli", "-p", "26379", "ping" ]
readinessProbe:
<<: *healthcheck

# Sidecar
- name: sidecar
image: commercialtribe/redis-sentinel-sidecar:latest
imagePullPolicy: Always
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: pod-info
mountPath: /etc/pod-info
readinessProbe:
exec:
command: [ "cat", "booted" ]

volumes:
- name: pod-info
downwardAPI:
items:
- path: labels
fieldRef:
fieldPath: metadata.labels
- name: redis-config
configMap:
name: redis-sentinel
volumeClaimTemplates:
- metadata:
name: data
annotations:
volume.beta.kubernetes.io/storage-class: "ssd"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 20Gi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: redis
name: redis-nodes
labels:
name: redis
service: redis
spec:
clusterIP: None
ports:
- port: 6379
name: redis
selector:
service: redis
name: redis-node
13 changes: 13 additions & 0 deletions k8s/redis-readonly-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: redis-readonly
labels:
service: redis
spec:
ports:
- port: 6379
name: redis
selector:
name: redis-sentinel-node
role: slave
29 changes: 0 additions & 29 deletions k8s/shared/redis-config-map.yaml

This file was deleted.

63 changes: 0 additions & 63 deletions k8s/shared/redis-stateful-set.yaml

This file was deleted.

Loading

0 comments on commit 30ee361

Please sign in to comment.