mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
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
This commit is contained in:
parent
0da12c1ba9
commit
25cca64c12
@ -10,6 +10,12 @@ Setting up a [rethinkdb](http://rethinkdb.com/) cluster on [kubernetes](http://k
|
||||
|
||||
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**
|
||||
|
||||
@ -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
|
||||
|
||||
```shell
|
||||
kubectl create -f driver-service.yaml
|
||||
$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
|
||||
NAME LABELS SELECTOR IP(S) PORT(S)
|
||||
rethinkdb-driver db=influxdb db=rethinkdb 10.0.27.114 28015/TCP
|
||||
```
|
||||
|
||||
**Step 2**
|
||||
@ -33,7 +39,7 @@ rethinkdb-driver db=influxdb db=rethinkdb 10.241.105.47
|
||||
start fist server in cluster
|
||||
|
||||
```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`
|
||||
@ -42,8 +48,9 @@ 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
|
||||
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!**
|
||||
@ -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
|
||||
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
|
||||
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
|
||||
@ -81,12 +91,28 @@ 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
|
||||
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
|
||||
```
|
||||
|
||||
open a web browser and access to *http://10.241.220.209:8080* to manage you cluster
|
||||
We request for an external load balancer in the admin-service.yaml file:
|
||||
|
||||
```
|
||||
createExternalLoadBalancer: true
|
||||
```
|
||||
|
||||
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?**
|
||||
|
||||
@ -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`.
|
||||
|
||||
* `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
|
||||
|
@ -1,30 +1,25 @@
|
||||
apiVersion: v1beta1
|
||||
namespace: rethinkdb
|
||||
apiVersion: v1beta3
|
||||
kind: Pod
|
||||
id: rethinkdb-admin-1.16.0
|
||||
labels:
|
||||
db: rethinkdb
|
||||
role: admin
|
||||
desiredState:
|
||||
manifest:
|
||||
version: v1beta1
|
||||
id: rethinkdb
|
||||
containers:
|
||||
- name: rethinkdb
|
||||
image: antmanler/rethinkdb:1.16.0
|
||||
ports:
|
||||
- name: admin-port
|
||||
containerPort: 8080
|
||||
- name: driver-port
|
||||
containerPort: 28015
|
||||
- name: cluster-port
|
||||
containerPort: 29015
|
||||
volumeMounts:
|
||||
- name: rethinkdb-storage
|
||||
mountPath: /data/rethinkdb_data
|
||||
volumes:
|
||||
- name: rethinkdb-storage
|
||||
source:
|
||||
emptyDir: {}
|
||||
restartPolicy:
|
||||
always: {}
|
||||
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: {}
|
||||
|
@ -1,11 +1,15 @@
|
||||
apiVersion: v1beta1
|
||||
namespace: rethinkdb
|
||||
apiVersion: v1beta3
|
||||
kind: Service
|
||||
id: rethinkdb-admin
|
||||
port: 8080
|
||||
containerPort: 8080
|
||||
labels:
|
||||
db: influxdb
|
||||
selector:
|
||||
db: rethinkdb
|
||||
role: admin
|
||||
metadata:
|
||||
labels:
|
||||
db: influxdb
|
||||
name: rethinkdb-admin
|
||||
namespace: rethinkdb
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
createExternalLoadBalancer: true
|
||||
selector:
|
||||
db: rethinkdb
|
||||
role: admin
|
||||
|
@ -1,10 +1,13 @@
|
||||
apiVersion: v1beta1
|
||||
namespace: rethinkdb
|
||||
apiVersion: v1beta3
|
||||
kind: Service
|
||||
id: rethinkdb-driver
|
||||
port: 28015
|
||||
containerPort: 28015
|
||||
labels:
|
||||
db: influxdb
|
||||
selector:
|
||||
db: rethinkdb
|
||||
metadata:
|
||||
labels:
|
||||
db: influxdb
|
||||
name: rethinkdb-driver
|
||||
namespace: rethinkdb
|
||||
spec:
|
||||
ports:
|
||||
- port: 28015
|
||||
targetPort: 28015
|
||||
selector:
|
||||
db: rethinkdb
|
||||
|
@ -32,41 +32,42 @@ if [[ ${NAME} == "admin" ]]; then
|
||||
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: v1beta1
|
||||
namespace: rethinkdb
|
||||
apiVersion: v1beta3
|
||||
kind: Pod
|
||||
id: rethinkdb-${NAME}-${VERSION}
|
||||
${NODE}
|
||||
labels:
|
||||
db: rethinkdb
|
||||
${ADMIN}
|
||||
desiredState:
|
||||
manifest:
|
||||
version: v1beta1
|
||||
id: rethinkdb
|
||||
containers:
|
||||
- name: rethinkdb
|
||||
image: antmanler/rethinkdb:${VERSION}
|
||||
ports:
|
||||
- name: admin-port
|
||||
containerPort: 8080
|
||||
- name: driver-port
|
||||
containerPort: 28015
|
||||
- name: cluster-port
|
||||
containerPort: 29015
|
||||
volumeMounts:
|
||||
- name: rethinkdb-storage
|
||||
mountPath: /data/rethinkdb_data
|
||||
volumes:
|
||||
- name: rethinkdb-storage
|
||||
source:
|
||||
hostDir:
|
||||
path: /data/db/rethinkdb
|
||||
restartPolicy:
|
||||
always: {}
|
||||
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
|
||||
|
@ -22,8 +22,8 @@ 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/v1beta1/endpoints/rethinkdb-driver?namespace=${NAMESPACE}"
|
||||
IP=$(curl -s ${URL} | jq -s -r --arg h "${MYHOST}" '.[0].endpoints | [ .[]? | split(":") ] | map(select(.[0] != $h)) | .[0][0]') || exit 1
|
||||
URL="${KUBERNETES_RO_SERVICE_HOST}/api/v1beta3/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
|
||||
|
||||
|
@ -1,36 +1,34 @@
|
||||
apiVersion: v1beta1
|
||||
namespace: rethinkdb
|
||||
apiVersion: v1beta3
|
||||
kind: ReplicationController
|
||||
id: rethinkdb-rc-1.16.0
|
||||
labels:
|
||||
db: rethinkdb
|
||||
desiredState:
|
||||
metadata:
|
||||
labels:
|
||||
db: rethinkdb
|
||||
name: rethinkdb-rc-1.16.0
|
||||
namespace: rethinkdb
|
||||
spec:
|
||||
replicas: 1
|
||||
replicaSelector:
|
||||
selector:
|
||||
db: rethinkdb
|
||||
role: replicas
|
||||
podTemplate:
|
||||
labels:
|
||||
db: rethinkdb
|
||||
role: replicas
|
||||
desiredState:
|
||||
manifest:
|
||||
version: v1beta1
|
||||
id: rethinkdb
|
||||
containers:
|
||||
- name: rethinkdb
|
||||
image: antmanler/rethinkdb:1.16.0
|
||||
ports:
|
||||
- name: admin-port
|
||||
containerPort: 8080
|
||||
- name: driver-port
|
||||
containerPort: 28015
|
||||
- name: cluster-port
|
||||
containerPort: 29015
|
||||
volumeMounts:
|
||||
- name: rethinkdb-storage
|
||||
mountPath: /data/rethinkdb_data
|
||||
volumes:
|
||||
- name: rethinkdb-storage
|
||||
source:
|
||||
emptyDir: {}
|
||||
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: {}
|
||||
|
@ -1,106 +0,0 @@
|
||||
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
|
@ -1,25 +0,0 @@
|
||||
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: {}
|
@ -1,14 +0,0 @@
|
||||
apiVersion: v1beta3
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
db: influxdb
|
||||
name: rethinkdb-admin
|
||||
namespace: rethinkdb
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
selector:
|
||||
db: rethinkdb
|
||||
role: admin
|
@ -1,13 +0,0 @@
|
||||
apiVersion: v1beta3
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
db: influxdb
|
||||
name: rethinkdb-driver
|
||||
namespace: rethinkdb
|
||||
spec:
|
||||
ports:
|
||||
- port: 28015
|
||||
targetPort: 28015
|
||||
selector:
|
||||
db: rethinkdb
|
@ -1,34 +0,0 @@
|
||||
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: {}
|
Loading…
Reference in New Issue
Block a user