Cloning docs for 0.20.0

This commit is contained in:
Brendan Burns
2015-06-25 20:07:34 -07:00
parent 712f303350
commit 82f7303a00
538 changed files with 95131 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
RethinkDB Cluster on Kubernetes
==============================
Setting up a [rethinkdb](http://rethinkdb.com/) cluster on [kubernetes](http://kubernetes.io)
**Features**
* Auto configuration cluster by querying info from k8s
* Simple
Quick start
-----------
**Step 0**
change the namespace of the current context to "rethinkdb"
```
$kubectl config view -o template --template='{{index . "current-context"}}' | xargs -I {} kubectl config set-context {} --namespace=rethinkdb
```
**Step 1**
antmanler/rethinkdb will discover peer using endpoints provided by kubernetes_ro service,
so first create a service so the following pod can query its endpoint
```shell
$kubectl create -f driver-service.yaml
```
check out:
```shell
$kubectl get se
NAME LABELS SELECTOR IP(S) PORT(S)
rethinkdb-driver db=influxdb db=rethinkdb 10.0.27.114 28015/TCP
```
**Step 2**
start fist server in cluster
```shell
$kubectl create -f rc.yaml
```
Actually, you can start servers as many as you want at one time, just modify the `replicas` in `rc.ymal`
check out again:
```shell
$kubectl get po
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
rethinkdb-rc-1.16.0-6odi0 kubernetes-minion-s59e/ db=rethinkdb,role=replicas Pending 11 seconds
rethinkdb antmanler/rethinkdb:1.16.0
```
**Done!**
---
Scale
-----
You can scale up you cluster using `kubectl scale`, and new pod will join to exsits cluster automatically, for example
```shell
$kubectl scale rc rethinkdb-rc-1.16.0 --replicas=3
scaled
$kubectl get po
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
rethinkdb-rc-1.16.0-6odi0 10.244.3.3 kubernetes-minion-s59e/104.197.79.42 db=rethinkdb,role=replicas Running About a minute
rethinkdb antmanler/rethinkdb:1.16.0 Running About a minute
rethinkdb-rc-1.16.0-e3mxv kubernetes-minion-d7ub/ db=rethinkdb,role=replicas Pending 6 seconds
rethinkdb antmanler/rethinkdb:1.16.0
rethinkdb-rc-1.16.0-manu6 kubernetes-minion-cybz/ db=rethinkdb,role=replicas Pending 6 seconds
rethinkdb antmanler/rethinkdb:1.16.0
```
Admin
-----
You need a separate pod (labeled as role:admin) to access Web Admin UI
```shell
kubectl create -f admin-pod.yaml
kubectl create -f admin-service.yaml
```
find the service
```shell
$kubectl get se
NAME LABELS SELECTOR IP(S) PORT(S)
rethinkdb-admin db=influxdb db=rethinkdb,role=admin 10.0.131.19 8080/TCP
104.197.19.120
rethinkdb-driver db=influxdb db=rethinkdb 10.0.27.114 28015/TCP
```
We request for an external load balancer in the [admin-service.yaml](admin-service.yaml) file:
```
type: LoadBalancer
```
The external load balancer allows us to access the service from outside via an external IP, which is 104.197.19.120 in this case.
Note that you may need to create a firewall rule to allow the traffic, assuming you are using GCE:
```
$ gcloud compute firewall-rules create rethinkdb --allow=tcp:8080
```
Now you can open a web browser and access to *http://104.197.19.120:8080* to manage your cluster.
**Why not just using pods in replicas?**
This is because kube-proxy will act as a load balancer and send your traffic to different server,
since the ui is not stateless when playing with Web Admin UI will cause `Connection not open on server` error.
- - -
**BTW**
* All services and pods are placed under namespace `rethinkdb`.
* `gen_pod.sh` is using to generate pod templates for my local cluster,
the generated pods which is using `nodeSelector` to force k8s to schedule containers to my designate nodes, for I need to access persistent data on my host dirs. Note that one needs to label the node before 'nodeSelector' can work, see this [tutorial](https://github.com/GoogleCloudPlatform/kubernetes/tree/master/examples/node-selection)
* see [antmanler/rethinkdb-k8s](https://github.com/antmanler/rethinkdb-k8s) for detail
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/rethinkdb/README.md?pixel)]()
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/release-0.20.0/examples/rethinkdb/README.md?pixel)]()

View File

@@ -0,0 +1,25 @@
apiVersion: v1
kind: Pod
metadata:
labels:
db: rethinkdb
role: admin
name: rethinkdb-admin-1.16.0
namespace: rethinkdb
spec:
containers:
- image: antmanler/rethinkdb:1.16.0
name: rethinkdb
ports:
- containerPort: 8080
name: admin-port
- containerPort: 28015
name: driver-port
- containerPort: 29015
name: cluster-port
volumeMounts:
- mountPath: /data/rethinkdb_data
name: rethinkdb-storage
volumes:
- name: rethinkdb-storage
emptyDir: {}

View File

@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
db: influxdb
name: rethinkdb-admin
namespace: rethinkdb
spec:
ports:
- port: 8080
targetPort: 8080
type: LoadBalancer
selector:
db: rethinkdb
role: admin

View File

@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
labels:
db: influxdb
name: rethinkdb-driver
namespace: rethinkdb
spec:
ports:
- port: 28015
targetPort: 28015
selector:
db: rethinkdb

View File

@@ -0,0 +1,73 @@
#!/bin/bash
# Copyright 2015 The Kubernetes Authors 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.
set -o errexit
set -o nounset
set -o pipefail
: ${VERSION:=1.16.0}
readonly NAME=${1-}
if [[ -z "${NAME}" ]]; then
echo -e "\033[1;31mName must be specified\033[0m"
exit 1
fi
ADMIN=""
if [[ ${NAME} == "admin" ]]; then
ADMIN="role: admin"
fi
NODE=""
# One needs to label a node with the same key/value pair,
# i.e., 'kubectl label nodes <node-name> name=${2}'
if [[ ! -z "${2-}" ]]; then
NODE="nodeSelector: { name: ${2} }"
fi
cat << EOF
apiVersion: v1
kind: Pod
metadata:
labels:
${ADMIN}
db: rethinkdb
name: rethinkdb-${NAME}-${VERSION}
namespace: rethinkdb
spec:
containers:
- image: antmanler/rethinkdb:${VERSION}
name: rethinkdb
ports:
- containerPort: 8080
name: admin-port
protocol: TCP
- containerPort: 28015
name: driver-port
protocol: TCP
- containerPort: 29015
name: cluster-port
protocol: TCP
volumeMounts:
- mountPath: /data/rethinkdb_data
name: rethinkdb-storage
${NODE}
restartPolicy: Always
volumes:
- hostPath:
path: /data/db/rethinkdb
name: rethinkdb-storage
EOF

View File

@@ -0,0 +1,14 @@
FROM rethinkdb:1.16.0
MAINTAINER BinZhao <wo@zhaob.in>
RUN apt-get update && \
apt-get install -yq curl && \
rm -rf /var/cache/apt/* && rm -rf /var/lib/apt/lists/* && \
curl -L http://stedolan.github.io/jq/download/linux64/jq > /usr/bin/jq && \
chmod u+x /usr/bin/jq
COPY ./run.sh /usr/bin/run.sh
RUN chmod u+x /usr/bin/run.sh
CMD ["/usr/bin/run.sh"]

View File

@@ -0,0 +1,37 @@
#!/bin/bash
# Copyright 2015 The Kubernetes Authors 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.
set -o pipefail
IP=""
if [[ -n "${KUBERNETES_RO_SERVICE_HOST}" ]]; then
: ${NAMESPACE:=rethinkdb}
# try to pick up first different ip from endpoints
MYHOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
URL="${KUBERNETES_RO_SERVICE_HOST}/api/v1/namespaces/${NAMESPACE}/endpoints/rethinkdb-driver"
IP=$(curl -s ${URL} | jq -s -r --arg h "${MYHOST}" '.[0].subsets | .[].addresses | [ .[].IP ] | map(select(. != $h)) | .[0]') || exit 1
[[ "${IP}" == null ]] && IP=""
fi
if [[ -n "${IP}" ]]; then
ENDPOINT="${IP}:29015"
echo "Join to ${ENDPOINT}"
exec rethinkdb --bind all --join ${ENDPOINT}
else
echo "Start single instance"
exec rethinkdb --bind all
fi

View File

@@ -0,0 +1,34 @@
apiVersion: v1
kind: ReplicationController
metadata:
labels:
db: rethinkdb
name: rethinkdb-rc-1.16.0
namespace: rethinkdb
spec:
replicas: 1
selector:
db: rethinkdb
role: replicas
template:
metadata:
labels:
db: rethinkdb
role: replicas
spec:
containers:
- image: antmanler/rethinkdb:1.16.0
name: rethinkdb
ports:
- containerPort: 8080
name: admin-port
- containerPort: 28015
name: driver-port
- containerPort: 29015
name: cluster-port
volumeMounts:
- mountPath: /data/rethinkdb_data
name: rethinkdb-storage
volumes:
- name: rethinkdb-storage
emptyDir: {}