Docker Swarm and Service Mode to create Couchbase Cluster explained how to create a Couchbase Cluster using Docker. It used the concept of a “master” and a “worker” service to simplify and automate the creation of cluster. The homogenous cluster was then created as shown in the architecture diagram below:
Complete details and background are in the Couchbase Cluster using Docker blog.
Docker 1.13 was released last week. A new feature in that release allows to deploy multi-container application defined using Docker Compose to multi-host enabled using Swarm mode. Ideally, we’d like to have a single Docker Compose definition that allows to start “master” service and start/scale “worker” service. But the “master” service, more importantly the container within the service, needs to be fully up before the “worker” service can be started. This is because the containers in the “worker” service register with the container in the “master” service to create the cluster. This typically require a bit of handcrafting as defined at Controlling Startup Order in Compose. So we’ll come back to that version later.
This blog will provide a quick refresh of the steps from the original using Docker 1.13. Read this blog for a quick how and the original blog for more details on why.
Create network:
1 2 3 |
docker network create -d overlay couchbase |
Check the created network using docker network ls
command:
1 2 3 4 5 6 7 |
NETWORK ID NAME DRIVER SCOPE 20a28d56f140 bridge bridge local 5maq7fyqdemx couchbase overlay swarm cd14345ec130 docker_gwbridge bridge local 46a19cdead82 host host local p1kbq62oxmn9 ingress overlay swarm 1b64333f45ec none null local |
Create Couchbase “master” service:
1 2 3 4 5 6 7 |
docker service create --name couchbase-master --replicas 1 -p 8091:8091 --network couchbase -e TYPE=MASTER arungupta/couchbase |
Check the created service using docker service ls
command:
1 2 |
ID NAME MODE REPLICAS IMAGE v5m0owjs4qo3 couchbase-master replicated 1/1 arungupta/couchbase:latest |
Create Couchbase “worker” service:
1 2 3 4 5 6 7 8 |
docker service create --name couchbase-worker --replicas 1 --network couchbase -e TYPE=WORKER -e COUCHBASE_MASTER=couchbase-master.couchbase -e AUTO_REBALANCE=false arungupta/couchbase |
Check the created service again using docker service ls
command:
1 2 3 |
ID NAME MODE REPLICAS IMAGE v5m0owjs4qo3 couchbase-master replicated 1/1 arungupta/couchbase:latest zqqqk76cu1jw couchbase-worker replicated 1/1 arungupta/couchbase:latest |
Check the worker service logs using newly introduced command docker service logs couchbase-worker
command. This command, newly introduced in Docker 1.13, pulls logs from all containers in the service and streams them to your console. There is no need to track down which containers are running on which hosts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
couchbase-worker.1.3x52hro26166@moby | ++ set -m couchbase-worker.1.3x52hro26166@moby | ++ sleep 15 couchbase-worker.1.3x52hro26166@moby | ++ /entrypoint.sh couchbase-server couchbase-worker.1.3x52hro26166@moby | Starting Couchbase Server -- Web UI available at http://:8091 and logs available in /opt/couchbase/var/lib/couchbase/logs couchbase-worker.1.3x52hro26166@moby | ++ curl -v -X POST http://127.0.0.1:8091/pools/default -d memoryQuota=300 -d indexMemoryQuota=300 couchbase-worker.1.3x52hro26166@moby | Note: Unnecessary use of -X or --request, POST is already inferred. couchbase-worker.1.3x52hro26166@moby | * Trying 127.0.0.1... couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-worker.1.3x52hro26166@moby | > POST /pools/default HTTP/1.1 couchbase-worker.1.3x52hro26166@moby | > Host: 127.0.0.1:8091 couchbase-worker.1.3x52hro26166@moby | > User-Agent: curl/7.49.1-DEV couchbase-worker.1.3x52hro26166@moby | > Accept: */* couchbase-worker.1.3x52hro26166@moby | > Content-Length: 36 couchbase-worker.1.3x52hro26166@moby | > Content-Type: application/x-www-form-urlencoded couchbase-worker.1.3x52hro26166@moby | > couchbase-worker.1.3x52hro26166@moby | } [36 bytes data] couchbase-worker.1.3x52hro26166@moby | * upload completely sent off: 36 out of 36 bytes couchbase-worker.1.3x52hro26166@moby | < HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | < Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | < Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | < Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | < Content-Length: 0 couchbase-worker.1.3x52hro26166@moby | < Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | < 100 36 0 0 100 36 0 13057 --:--:-- --:--:-- --:--:-- 18000 couchbase-worker.1.3x52hro26166@moby | * Connection #0 to host 127.0.0.1 left intact couchbase-worker.1.3x52hro26166@moby | ++ curl -v http://127.0.0.1:8091/node/controller/setupServices -d services=kv%2Cn1ql%2Cindex couchbase-worker.1.3x52hro26166@moby | * Trying 127.0.0.1... couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-worker.1.3x52hro26166@moby | > POST /node/controller/setupServices HTTP/1.1 couchbase-worker.1.3x52hro26166@moby | > Host: 127.0.0.1:8091 couchbase-worker.1.3x52hro26166@moby | > User-Agent: curl/7.49.1-DEV couchbase-worker.1.3x52hro26166@moby | > Accept: */* couchbase-worker.1.3x52hro26166@moby | > Content-Length: 26 couchbase-worker.1.3x52hro26166@moby | > Content-Type: application/x-www-form-urlencoded couchbase-worker.1.3x52hro26166@moby | > couchbase-worker.1.3x52hro26166@moby | } [26 bytes data] couchbase-worker.1.3x52hro26166@moby | * upload completely sent off: 26 out of 26 bytes couchbase-worker.1.3x52hro26166@moby | < HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | < Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | < Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | < Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | < Content-Length: 0 couchbase-worker.1.3x52hro26166@moby | < Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | < 100 26 0 0 100 26 0 13171 --:--:-- --:--:-- --:--:-- 26000 couchbase-worker.1.3x52hro26166@moby | * Connection #0 to host 127.0.0.1 left intact couchbase-worker.1.3x52hro26166@moby | ++ curl -v http://127.0.0.1:8091/settings/web -d port=8091 -d username=Administrator -d password=password couchbase-worker.1.3x52hro26166@moby | * Trying 127.0.0.1... couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-worker.1.3x52hro26166@moby | > POST /settings/web HTTP/1.1 couchbase-worker.1.3x52hro26166@moby | > Host: 127.0.0.1:8091 couchbase-worker.1.3x52hro26166@moby | > User-Agent: curl/7.49.1-DEV couchbase-worker.1.3x52hro26166@moby | > Accept: */* couchbase-worker.1.3x52hro26166@moby | > Content-Length: 50 couchbase-worker.1.3x52hro26166@moby | > Content-Type: application/x-www-form-urlencoded couchbase-worker.1.3x52hro26166@moby | > couchbase-worker.1.3x52hro26166@moby | } [50 bytes data] couchbase-worker.1.3x52hro26166@moby | * upload completely sent off: 50 out of 50 bytes couchbase-worker.1.3x52hro26166@moby | < HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | < Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | < Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | < Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | < Content-Type: application/json couchbase-worker.1.3x52hro26166@moby | < Content-Length: 39 couchbase-worker.1.3x52hro26166@moby | < Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | < couchbase-worker.1.3x52hro26166@moby | { [39 bytes data] 100 89 100 39 100 50 3423 4389 --:--:-- --:--:-- --:--:-- 4545 couchbase-worker.1.3x52hro26166@moby | * Connection #0 to host 127.0.0.1 left intact couchbase-worker.1.3x52hro26166@moby | ++ curl -i -u Administrator:password -X POST http://127.0.0.1:8091/settings/indexes -d storageMode=memory_optimized couchbase-worker.1.3x52hro26166@moby | % Total % Received % Xferd Average Speed Time Time Time Current couchbase-worker.1.3x52hro26166@moby | Dload Upload Total Spent Left Speed 100 180 100 152 100 28 13264 2443 --:--:-- --:--:-- --:--:-- 13818 couchbase-worker.1.3x52hro26166@moby | {"newBaseUri":"http://127.0.0.1:8091/"}HTTP/1.1 200 OK couchbase-worker.1.3x52hro26166@moby | Server: Couchbase Server couchbase-worker.1.3x52hro26166@moby | Pragma: no-cache couchbase-worker.1.3x52hro26166@moby | Date: Sun, 22 Jan 2017 22:01:15 GMT couchbase-worker.1.3x52hro26166@moby | Content-Type: application/json couchbase-worker.1.3x52hro26166@moby | Content-Length: 152 couchbase-worker.1.3x52hro26166@moby | Cache-Control: no-cache couchbase-worker.1.3x52hro26166@moby | couchbase-worker.1.3x52hro26166@moby | ++ echo 'Type: WORKER' couchbase-worker.1.3x52hro26166@moby | ++ '[' WORKER = WORKER ']' couchbase-worker.1.3x52hro26166@moby | ++ echo 'Sleeping ...' couchbase-worker.1.3x52hro26166@moby | ++ sleep 15 couchbase-worker.1.3x52hro26166@moby | {"storageMode":"memory_optimized","indexerThreads":0,"memorySnapshotInterval":200,"stableSnapshotInterval":5000,"maxRollbackPoints":5,"logLevel":"info"}Type: WORKER couchbase-worker.1.3x52hro26166@moby | Sleeping ... couchbase-worker.1.3x52hro26166@moby | +++ hostname -I couchbase-worker.1.3x52hro26166@moby | +++ cut -d ' ' -f1 couchbase-worker.1.3x52hro26166@moby | ++ IP=10.0.0.5 couchbase-worker.1.3x52hro26166@moby | ++ echo 'IP: ' 10.0.0.5 couchbase-worker.1.3x52hro26166@moby | ++ echo 'Auto Rebalance: false' couchbase-worker.1.3x52hro26166@moby | IP: 10.0.0.5 couchbase-worker.1.3x52hro26166@moby | ++ '[' false = true ']' couchbase-worker.1.3x52hro26166@moby | ++ couchbase-cli server-add --cluster=couchbase-master.couchbase:8091 --user=Administrator --password=password --server-add=10.0.0.5 --server-add-username=Administrator --server-add-password=password couchbase-worker.1.3x52hro26166@moby | Auto Rebalance: false couchbase-worker.1.3x52hro26166@moby | Warning: Adding server from group-manage is deprecated couchbase-worker.1.3x52hro26166@moby | Server 10.0.0.5:8091 added couchbase-worker.1.3x52hro26166@moby | ++ fg 1 couchbase-worker.1.3x52hro26166@moby | /entrypoint.sh couchbase-server |
Complete logs show how the “worker” service was created and joined the cluster originally created by “master”.
Scale the cluster by scaling the Docker service:
1 |
docker service scale couchbase-worker=2 |
Check the service again using docker service ls
command:
1 2 3 |
ID NAME MODE REPLICAS IMAGE v5m0owjs4qo3 couchbase-master replicated 1/1 arungupta/couchbase:latest zqqqk76cu1jw couchbase-worker replicated 2/2 arungupta/couchbase:latest |
Now you’ve a three node Couchbase cluster. Before rebalancing the cluster, let’s quickly check what does Couchbase Web Console shows.
Couchbase Web Console is accessible at http://localhost:8091 and shows a single Couchbase node with data, index and query service. This node was created using “master” service. Two additional nodes created using “worker” service are shown in Pending Rebalance
tab:
Click on Rebalance to rebalance
the cluster and see the fully rebalanced cluster:
Want to get started with Couchbase? Look at Couchbase Starter Kits.
Want to learn more about running Couchbase in containers?
[…] may also consider running Couchbase Cluster using Docker or read more about Deploying Docker Services to […]