Commit 25cca64c authored by Chao Xu's avatar Chao Xu

update example/rethinkdb to v1beta3

add external load balancer to work on GCE add a comment about nodeSelector in gen-pod.sh update the image/run.sh to v1beta3
parent 0da12c1b
...@@ -10,6 +10,12 @@ Setting up a [rethinkdb](http://rethinkdb.com/) cluster on [kubernetes](http://k ...@@ -10,6 +10,12 @@ Setting up a [rethinkdb](http://rethinkdb.com/) cluster on [kubernetes](http://k
Quick start 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** **Step 1**
...@@ -17,15 +23,15 @@ antmanler/rethinkdb will discover peer using endpoints provided by kubernetes_ro ...@@ -17,15 +23,15 @@ antmanler/rethinkdb will discover peer using endpoints provided by kubernetes_ro
so first create a service so the following pod can query its endpoint so first create a service so the following pod can query its endpoint
```shell ```shell
kubectl create -f driver-service.yaml $kubectl create -f driver-service.yaml
``` ```
check out: check out:
```shell ```shell
$kubectl get se $kubectl get se
NAME LABELS SELECTOR IP PORT NAME LABELS SELECTOR IP(S) PORT(S)
rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47 28015 rethinkdb-driver db=influxdb db=rethinkdb 10.0.27.114 28015/TCP
``` ```
**Step 2** **Step 2**
...@@ -33,7 +39,7 @@ rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47 ...@@ -33,7 +39,7 @@ rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47
start fist server in cluster start fist server in cluster
```shell ```shell
kubectl create -f rc.yaml $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` Actually, you can start servers as many as you want at one time, just modify the `replicas` in `rc.ymal`
...@@ -42,8 +48,9 @@ check out again: ...@@ -42,8 +48,9 @@ check out again:
```shell ```shell
$kubectl get po $kubectl get po
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
99f6d361-abd6-11e4-a1ea-001c426dbc28 10.240.2.68 rethinkdb rethinkdb:1.16.0 10.245.2.2/ db=rethinkdb,role=replicas Running rethinkdb-rc-1.16.0-6odi0 kubernetes-minion-s59e/ db=rethinkdb,role=replicas Pending 11 seconds
rethinkdb antmanler/rethinkdb:1.16.0
``` ```
**Done!** **Done!**
...@@ -61,10 +68,13 @@ You can scale up you cluster using `kubectl resize`, and new pod will join to ex ...@@ -61,10 +68,13 @@ You can scale up you cluster using `kubectl resize`, and new pod will join to ex
$kubectl resize rc rethinkdb-rc-1.16.0 --replicas=3 $kubectl resize rc rethinkdb-rc-1.16.0 --replicas=3
resized resized
$kubectl get po $kubectl get po
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
99f6d361-abd6-11e4-a1ea-001c426dbc28 10.240.2.68 rethinkdb rethinkdb:1.16.0 10.245.2.2/ db=rethinkdb,role=replicas Running 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
d10182b5-abd6-11e4-a1ea-001c426dbc28 10.240.26.14 rethinkdb rethinkdb:1.16.0 10.245.2.4/ db=rethinkdb,role=replicas Running rethinkdb antmanler/rethinkdb:1.16.0 Running About a minute
d101c1a4-abd6-11e4-a1ea-001c426dbc28 10.240.11.14 rethinkdb rethinkdb:1.16.0 10.245.2.3/ db=rethinkdb,role=replicas Running 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 Admin
...@@ -81,12 +91,28 @@ find the service ...@@ -81,12 +91,28 @@ find the service
```shell ```shell
$kubectl get se $kubectl get se
NAME LABELS SELECTOR IP PORT NAME LABELS SELECTOR IP(S) PORT(S)
rethinkdb-admin db=influxdb db=rethinkdb,role=admin 10.241.220.209 8080 rethinkdb-admin db=influxdb db=rethinkdb,role=admin 10.0.131.19 8080/TCP
rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47 28015 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 file:
```
createExternalLoadBalancer: true
``` ```
open a web browser and access to *http://10.241.220.209:8080* to manage you cluster 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?** **Why not just using pods in replicas?**
...@@ -101,6 +127,6 @@ since the ui is not stateless when playing with Web Admin UI will cause `Connect ...@@ -101,6 +127,6 @@ since the ui is not stateless when playing with Web Admin UI will cause `Connect
* All services and pods are placed under namespace `rethinkdb`. * All services and pods are placed under namespace `rethinkdb`.
* `gen_pod.sh` is using to generate pod templates for my local cluster, * `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. 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 * see [antmanler/rethinkdb-k8s](https://github.com/antmanler/rethinkdb-k8s) for detail
apiVersion: v1beta1 apiVersion: v1beta3
namespace: rethinkdb
kind: Pod kind: Pod
id: rethinkdb-admin-1.16.0 metadata:
labels: labels:
db: rethinkdb db: rethinkdb
role: admin role: admin
desiredState: name: rethinkdb-admin-1.16.0
manifest: namespace: rethinkdb
version: v1beta1 spec:
id: rethinkdb containers:
containers: - image: antmanler/rethinkdb:1.16.0
- name: rethinkdb name: rethinkdb
image: antmanler/rethinkdb:1.16.0 ports:
ports: - containerPort: 8080
- name: admin-port name: admin-port
containerPort: 8080 - containerPort: 28015
- name: driver-port name: driver-port
containerPort: 28015 - containerPort: 29015
- name: cluster-port name: cluster-port
containerPort: 29015 volumeMounts:
volumeMounts: - mountPath: /data/rethinkdb_data
- name: rethinkdb-storage name: rethinkdb-storage
mountPath: /data/rethinkdb_data volumes:
volumes: - name: rethinkdb-storage
- name: rethinkdb-storage emptyDir: {}
source:
emptyDir: {}
restartPolicy:
always: {}
apiVersion: v1beta1 apiVersion: v1beta3
namespace: rethinkdb
kind: Service kind: Service
id: rethinkdb-admin metadata:
port: 8080 labels:
containerPort: 8080 db: influxdb
labels: name: rethinkdb-admin
db: influxdb namespace: rethinkdb
selector: spec:
db: rethinkdb ports:
role: admin - port: 8080
targetPort: 8080
createExternalLoadBalancer: true
selector:
db: rethinkdb
role: admin
apiVersion: v1beta1 apiVersion: v1beta3
namespace: rethinkdb
kind: Service kind: Service
id: rethinkdb-driver metadata:
port: 28015 labels:
containerPort: 28015 db: influxdb
labels: name: rethinkdb-driver
db: influxdb namespace: rethinkdb
selector: spec:
db: rethinkdb ports:
- port: 28015
targetPort: 28015
selector:
db: rethinkdb
...@@ -32,41 +32,42 @@ if [[ ${NAME} == "admin" ]]; then ...@@ -32,41 +32,42 @@ if [[ ${NAME} == "admin" ]]; then
fi fi
NODE="" 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 if [[ ! -z "${2-}" ]]; then
NODE="nodeSelector: { name: ${2} }" NODE="nodeSelector: { name: ${2} }"
fi fi
cat << EOF cat << EOF
apiVersion: v1beta1 apiVersion: v1beta3
namespace: rethinkdb
kind: Pod kind: Pod
id: rethinkdb-${NAME}-${VERSION} metadata:
${NODE} labels:
labels: ${ADMIN}
db: rethinkdb db: rethinkdb
${ADMIN} name: rethinkdb-${NAME}-${VERSION}
desiredState: namespace: rethinkdb
manifest: spec:
version: v1beta1 containers:
id: rethinkdb - image: antmanler/rethinkdb:${VERSION}
containers: name: rethinkdb
- name: rethinkdb ports:
image: antmanler/rethinkdb:${VERSION} - containerPort: 8080
ports: name: admin-port
- name: admin-port protocol: TCP
containerPort: 8080 - containerPort: 28015
- name: driver-port name: driver-port
containerPort: 28015 protocol: TCP
- name: cluster-port - containerPort: 29015
containerPort: 29015 name: cluster-port
volumeMounts: protocol: TCP
- name: rethinkdb-storage volumeMounts:
mountPath: /data/rethinkdb_data - mountPath: /data/rethinkdb_data
volumes: name: rethinkdb-storage
- name: rethinkdb-storage ${NODE}
source: restartPolicy: Always
hostDir: volumes:
path: /data/db/rethinkdb - hostPath:
restartPolicy: path: /data/db/rethinkdb
always: {} name: rethinkdb-storage
EOF EOF
...@@ -22,8 +22,8 @@ if [[ -n "${KUBERNETES_RO_SERVICE_HOST}" ]]; then ...@@ -22,8 +22,8 @@ if [[ -n "${KUBERNETES_RO_SERVICE_HOST}" ]]; then
: ${NAMESPACE:=rethinkdb} : ${NAMESPACE:=rethinkdb}
# try to pick up first different ip from endpoints # try to pick up first different ip from endpoints
MYHOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') MYHOST=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
URL="${KUBERNETES_RO_SERVICE_HOST}/api/v1beta1/endpoints/rethinkdb-driver?namespace=${NAMESPACE}" URL="${KUBERNETES_RO_SERVICE_HOST}/api/v1beta3/namespaces/${NAMESPACE}/endpoints/rethinkdb-driver"
IP=$(curl -s ${URL} | jq -s -r --arg h "${MYHOST}" '.[0].endpoints | [ .[]? | split(":") ] | map(select(.[0] != $h)) | .[0][0]') || exit 1 IP=$(curl -s ${URL} | jq -s -r --arg h "${MYHOST}" '.[0].subsets | .[].addresses | [ .[].IP ] | map(select(. != $h)) | .[0]') || exit 1
[[ "${IP}" == null ]] && IP="" [[ "${IP}" == null ]] && IP=""
fi fi
......
apiVersion: v1beta1 apiVersion: v1beta3
namespace: rethinkdb
kind: ReplicationController kind: ReplicationController
id: rethinkdb-rc-1.16.0 metadata:
labels: labels:
db: rethinkdb db: rethinkdb
desiredState: name: rethinkdb-rc-1.16.0
namespace: rethinkdb
spec:
replicas: 1 replicas: 1
replicaSelector: selector:
db: rethinkdb db: rethinkdb
role: replicas role: replicas
podTemplate: template:
labels: metadata:
db: rethinkdb labels:
role: replicas db: rethinkdb
desiredState: role: replicas
manifest: spec:
version: v1beta1 containers:
id: rethinkdb - image: antmanler/rethinkdb:1.16.0
containers: name: rethinkdb
- name: rethinkdb ports:
image: antmanler/rethinkdb:1.16.0 - containerPort: 8080
ports: name: admin-port
- name: admin-port - containerPort: 28015
containerPort: 8080 name: driver-port
- name: driver-port - containerPort: 29015
containerPort: 28015 name: cluster-port
- name: cluster-port volumeMounts:
containerPort: 29015 - mountPath: /data/rethinkdb_data
volumeMounts: name: rethinkdb-storage
- name: rethinkdb-storage volumes:
mountPath: /data/rethinkdb_data - name: rethinkdb-storage
volumes: emptyDir: {}
- name: rethinkdb-storage
source:
emptyDir: {}
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 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 PORT
rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47 28015
```
**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
99f6d361-abd6-11e4-a1ea-001c426dbc28 10.240.2.68 rethinkdb rethinkdb:1.16.0 10.245.2.2/ db=rethinkdb,role=replicas Running
```
**Done!**
---
Scale
-----
You can scale up you cluster using `kubectl resize`, and new pod will join to exsits cluster automatically, for example
```shell
$kubectl resize rc rethinkdb-rc-1.16.0 --replicas=3
resized
$kubectl get po
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS
99f6d361-abd6-11e4-a1ea-001c426dbc28 10.240.2.68 rethinkdb rethinkdb:1.16.0 10.245.2.2/ db=rethinkdb,role=replicas Running
d10182b5-abd6-11e4-a1ea-001c426dbc28 10.240.26.14 rethinkdb rethinkdb:1.16.0 10.245.2.4/ db=rethinkdb,role=replicas Running
d101c1a4-abd6-11e4-a1ea-001c426dbc28 10.240.11.14 rethinkdb rethinkdb:1.16.0 10.245.2.3/ db=rethinkdb,role=replicas Running
```
Admin
-----
You need a separate pod (which labled 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 PORT
rethinkdb-admin db=influxdb db=rethinkdb,role=admin 10.241.220.209 8080
rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47 28015
```
open a web browser and access to *http://10.241.220.209:8080* to manage you 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.
* see [antmanler/rethinkdb-k8s](https://github.com/antmanler/rethinkdb-k8s) for detail
apiVersion: v1beta3
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: {}
apiVersion: v1beta3
kind: Service
metadata:
labels:
db: influxdb
name: rethinkdb-admin
namespace: rethinkdb
spec:
ports:
- port: 8080
targetPort: 8080
selector:
db: rethinkdb
role: admin
apiVersion: v1beta3
kind: Service
metadata:
labels:
db: influxdb
name: rethinkdb-driver
namespace: rethinkdb
spec:
ports:
- port: 28015
targetPort: 28015
selector:
db: rethinkdb
apiVersion: v1beta3
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: {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment