Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Couchbase PetSet example #2

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cluster-petset/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM couchbase

COPY configure-node.sh /opt/couchbase

CMD ["/opt/couchbase/configure-node.sh"]

44 changes: 44 additions & 0 deletions cluster-petset/configure-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set -m

/entrypoint.sh couchbase-server &

sleep 15

# Setup index and memory quota
curl -v -X POST http://127.0.0.1:8091/pools/default -d memoryQuota=300 -d indexMemoryQuota=300

# Setup services
curl -v http://127.0.0.1:8091/node/controller/setupServices -d services=kv%2Cn1ql%2Cindex

# Setup credentials
curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=Administrator -d password=password

# Setup Memory Optimized Indexes
curl -i -u Administrator:password -X POST http://127.0.0.1:8091/settings/indexes -d 'storageMode=memory_optimized'

# Load travel-sample bucket
curl -v -u Administrator:password -X POST http://127.0.0.1:8091/sampleBuckets/install -d '["travel-sample"]'

if [[ "$HOSTNAME" == *-0 ]]; then
TYPE="MASTER"
else
TYPE="WORKER"
fi

echo "Type: $TYPE"

if [ "$TYPE" = "WORKER" ]; then
sleep 15

IP=`hostname -I`

echo "Auto Rebalance: $AUTO_REBALANCE"
if [ "$AUTO_REBALANCE" = "true" ]; then
couchbase-cli rebalance --cluster=$COUCHBASE_MASTER:8091 --user=Administrator --password=password --server-add=$IP --server-add-username=Administrator --server-add-password=password
else
couchbase-cli server-add --cluster=$COUCHBASE_MASTER:8091 --user=Administrator --password=password --server-add=$IP --server-add-username=Administrator --server-add-password=password
fi;
fi;

fg 1

38 changes: 38 additions & 0 deletions cluster-petset/couchbase-petset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1alpha1
kind: PetSet
metadata:
name: couchbase
spec:
serviceName: "couchbase"
replicas: 2
template:
metadata:
labels:
app: couchbase
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
terminationGracePeriodSeconds: 0
containers:
- name: couchbase
image: saturnism/couchbase:k8s-petset
ports:
- containerPort: 8091
volumeMounts:
- name: couchbase-data
mountPath: /opt/couchbase/var
env:
- name: COUCHBASE_MASTER
value: "couchbase-0.couchbase.default.svc.cluster.local"
- name: AUTO_REBALANCE
value: "false"
volumeClaimTemplates:
- metadata:
name: couchbase-data
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
29 changes: 29 additions & 0 deletions cluster-petset/couchbase-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Service
metadata:
name: couchbase
labels:
app: couchbase
spec:
ports:
- port: 8091
name: couchbase
# *.couchbase.default.svc.cluster.local
clusterIP: None
selector:
app: couchbase
---
apiVersion: v1
kind: Service
metadata:
name: couchbase-ui
labels:
app: couchbase-ui
spec:
ports:
- port: 8091
name: couchbase
selector:
app: couchbase
sessionAffinity: ClientIP
type: LoadBalancer
37 changes: 37 additions & 0 deletions cluster-petset/readme.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
= Couchbase Cluster on Kubernetes

The files in this directory can serve as an example of how to deploy a Couchbase Server cluster on Kubernetes. Tested on GKE, Amazon as well as a self-deployed Kubernetes cluster.

== Usage

It should be noted at the beginning that this setup depends on KubeDNS to be enabled and functional to successfully deploy.

. Create the Service
+
```
kubectl apply -f couchbase-service.yml
```
+
This file will provision a LoadBalancer for the Web Console of the master node as well.
+

. Create the PetSet
+
```
kubectl apply -f couchbase-petset.yml
```
+
+
. Once the master is up and LB has been provisioned, connect to the WebUI by going to `$LOADBALANCER_IP:8091` in your browser
. Create either auto-rebalancing nodes or just attach the nodes to the cluster with one of the two worker files:

. Scale workers with the normal scaling commands for the PetSet
+
```
kubectl patch petset couchbase -p '{"spec":{"replicas":2}}'
```

=== Build your own image

. Create the image with `docker build -t $DESIRED_IMG_NAME .`
. Update all `.yml` files with your new image name if necessary.