Skip to content

Commit

Permalink
Add configuration for a redis example.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed Jan 22, 2015
1 parent a9cbc58 commit 7598ee4
Show file tree
Hide file tree
Showing 13 changed files with 1,938 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/redis/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM redis:2.8
RUN apt-get update
RUN apt-get install -yy -q python

COPY redis-master.conf /redis-master/redis.conf
COPY redis-slave.conf /redis-slave/redis.conf
COPY run.sh /run.sh
COPY sentinel.py /sentinel.py

CMD [ "/run.sh" ]
ENTRYPOINT [ "sh", "-c" ]
827 changes: 827 additions & 0 deletions examples/redis/image/redis-master.conf

Large diffs are not rendered by default.

827 changes: 827 additions & 0 deletions examples/redis/image/redis-slave.conf

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions examples/redis/image/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function launchmaster() {
if [[ ! -e /redis-master-data ]]; then
echo "Redis master data doesn't exist, data won't be persistent!"
mkdir /redis-master-data
fi
redis-server /redis-master/redis.conf
}

function launchsentinel() {
while true; do
master=$(redis-cli -h ${REDIS_SENTINEL_SERVICE_HOST} -p ${REDIS_SENTINEL_SERVICE_PORT} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
master="${master//\"}"
else
master=$(hostname -i)
fi

redis-cli -h ${master} INFO
if [[ "$?" == "0" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
sleep 10
done

sentinel_conf=sentinel.conf

echo "sentinel monitor mymaster ${master} 6379 2" > ${sentinel_conf}
echo "sentinel down-after-milliseconds mymaster 60000" >> ${sentinel_conf}
echo "sentinel failover-timeout mymaster 180000" >> ${sentinel_conf}
echo "sentinel parallel-syncs mymaster 1" >> ${sentinel_conf}

redis-sentinel ${sentinel_conf}
}

function launchslave() {
while true; do
master=$(redis-cli -h ${REDIS_SENTINEL_SERVICE_HOST} -p ${REDIS_SENTINEL_SERVICE_PORT} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
master="${master//\"}"
else
echo "Failed to find master."
sleep 60
exit 1
fi
redis-cli -h ${master} INFO
if [[ "$?" == "0" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
sleep 10
done
perl -pi -e "s/%master-ip%/${master}/" /redis-slave/redis.conf
perl -pi -e "s/%master-port%/6379/" /redis-slave/redis.conf
redis-server /redis-slave/redis.conf
}

if [[ "${MASTER}" == "true" ]]; then
launchmaster
exit 0
fi

if [[ "${SENTINEL}" == "true" ]]; then
launchsentinel
exit 0
fi

launchslave
29 changes: 29 additions & 0 deletions examples/redis/redis-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
id: redis
kind: ReplicationController
apiVersion: v1beta1
desiredState:
replicas: 1
replicaSelector:
name: redis
podTemplate:
desiredState:
manifest:
version: v1beta1
id: redis
containers:
- name: redis
image: kubernetes/redis
cpu: 1000
ports:
- name: api
containerPort: 6379
volumeMounts:
- name: data
mountPath: /redis-master-data
volumes:
- name: data
source:
emptyDir: {}
labels:
name: redis

10 changes: 10 additions & 0 deletions examples/redis/redis-master-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: redis-master
kind: Service
apiVersion: v1beta1
port: 6379
selector:
name: redis
role: master
labels:
name: master
role: service
38 changes: 38 additions & 0 deletions examples/redis/redis-master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
id: redis-master
kind: Pod
apiVersion: v1beta1
desiredState:
manifest:
version: v1beta1
id: redis-master
containers:
- name: master
image: kubernetes/redis
cpu: 1000
ports:
- name: api
containerPort: 6379
volumeMounts:
- name: data
mountPath: /redis-master-data
env:
- key: MASTER
value: "true"
- name: sentinel
image: kubernetes/redis
ports:
- name: api
containerPort: 26379
env:
- key: SENTINEL
value: "true"
volumes:
- name: data
source:
emptyDir: {}
labels:
name: redis
role: master
redis-sentinel: "true"


19 changes: 19 additions & 0 deletions examples/redis/redis-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
id: redis-proxy
kind: Pod
apiVersion: v1beta1
desiredState:
manifest:
version: v1beta1
id: redis-proxy
containers:
- name: proxy
image: kubernetes/redis-proxy
ports:
- name: api
containerPort: 6379
labels:
name: redis-proxy
role: proxy



26 changes: 26 additions & 0 deletions examples/redis/redis-sentinel-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
id: redis-sentinel
kind: ReplicationController
apiVersion: v1beta1
desiredState:
replicas: 1
replicaSelector:
redis-sentinel: "true"
podTemplate:
desiredState:
manifest:
version: v1beta1
id: redis-slave
containers:
- name: sentinel
image: kubernetes/redis
ports:
- name: api
containerPort: 26379
env:
- key: SENTINEL
value: "true"
labels:
name: redis-sentinel
role: sentinel
redis-sentinel: "true"

10 changes: 10 additions & 0 deletions examples/redis/redis-sentinel-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: redis-sentinel
kind: Service
apiVersion: v1beta1
port: 26379
containerPort: 26379
selector:
redis-sentinel: "true"
labels:
name: sentinel
role: service
22 changes: 22 additions & 0 deletions examples/redis/redis-sentinel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id: redis-sentinel
kind: Pod
apiVersion: v1beta1
desiredState:
manifest:
version: v1beta1
id: redis-sentinel
containers:
- name: sentinel
image: kubernetes/redis
ports:
- name: api
containerPort: 26379
env:
- key: SENTINEL
value: "true"
labels:
name: redis-sentinel
role: sentinel
redis-sentinel: "true"


9 changes: 9 additions & 0 deletions examples/redis/redis-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: redis
kind: Service
apiVersion: v1beta1
port: 6379
selector:
name: redis
labels:
name: read
role: service
26 changes: 26 additions & 0 deletions examples/redis/redis-slave.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
id: redis-slave
kind: Pod
apiVersion: v1beta1
desiredState:
manifest:
version: v1beta1
id: redis-slave
containers:
- name: slave
image: kubernetes/redis
cpu: 1000
ports:
- name: api
containerPort: 6379
volumeMounts:
- name: data
mountPath: /redis-master-data
volumes:
- name: data
source:
emptyDir: {}
labels:
name: redis



0 comments on commit 7598ee4

Please sign in to comment.