loading...
Aerospike

How do I get a 2 nodes Aerospike cluster running quickly in Docker without editing a single file?

volmarl profile image Lucien Volmar ・2 min read

Often we need to bring up a small Aerospike cluster for either functional testing or for development purposes.
There are zillion of tools available for deployment to production (helm+Kubernetes, docker swarm, docker-compose etc), but in some cases its not needed for a basic cluster running on an old mac book. Mine is a MacBook Pro (Retina, 15-inch, Late 2013, last one running in the office!)
To quickly bring up a 2 nodes cluster running the latest Aerospike CE server you can execute these commands at a terminal:

1. Execute 2 docker runs with different names:

docker run --rm -tid --name aerospike1 -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike/aerospike-server
docker run --rm -tid --name aerospike2 -p 6000:3000 -p 6001:3001 -p 6002:3002 -p 6003:3003 aerospike/aerospike-server

2. Get IP address of each node:

docker exec -ti aerospike1 asinfo -v service
docker exec -ti aerospike2 asinfo -v service

3. Run an asinfo -v tip command to form cluster:

docker exec -ti aerospike1 asinfo -v 'tip:host=<IP ADDRESS from aerospike2>;port=3002'

(replace ' with double quotes on Windows environments!)

I guess we could get fancy and automate the last line:

docker exec -e "AEROSPIKE2=$(docker exec -ti aerospike2 asinfo -v service|cut -d ':' -f1)" -ti aerospike1 asinfo -v 'tip:host=$AEROSPIKE2;port=3002'

Let's keep it simple for now!
Executing above command lines:

~/Development/test.docker $ docker run --rm -tid --name aerospike1 -p 3000:3000 -p 3001:3001 -p 3002:3002 -p 3003:3003 aerospike/aerospike-server
9a99d1163d7d674afc3789b46e41fe9e0b142930e814c59e7a8deda0b71fbb63
~/Development/test.docker $ docker run --rm -tid --name aerospike2 -p 6000:3000 -p 6001:3001 -p 6002:3002 -p 6003:3003 aerospike/aerospike-server
abbfed4bc8099e7614c4df387446907ef188497313310e670ae1b5778d439b01
~/Development/test.docker $ docker exec -ti aerospike1 asinfo -v service
172.17.0.2:3000
~/Development/test.docker $ docker exec -ti aerospike2 asinfo -v service
172.17.0.3:3000
docker exec -ti aerospike1 asinfo -v 'tip:host=172.17.0.3;port=3002'

Let us verify that we have a cluster running using asadm:

~/Development/test.docker $ docker exec -ti aerospike1 asadm
Seed:        [('127.0.0.1', 3000, None)]
Config_file: /root/.aerospike/astools.conf, /etc/aerospike/astools.conf
Aerospike Interactive Shell, version 0.3.3
Found 2 nodes
Online:  172.17.0.3:3000, 172.17.0.2:3000

Let us confirm containerized app connection using aerospike-tools container:

~/Development/test.docker $ docker run --rm -ti --name aerospike-tools aerospike/aerospike-tools aql -h 172.17.0.3
Seed:         172.17.0.3
User:         None
Config File:  /etc/aerospike/astools.conf /root/.aerospike/astools.conf 
Aerospike Query Client
Version 3.23.0
C Client Version 4.6.9
Copyright 2012-2019 Aerospike. All rights reserved.
aql> INSERT INTO test.demo (PK, foo, bar) VALUES ('key1', 123, 'abc')
OK, 1 record affected.
aql> select * from test.demo
+-----+-------+
| foo | bar   |
+-----+-------+
| 123 | "abc" |
+-----+-------+
1 row in set (0.147 secs)
OK

And that is it! we have a 2 nodes cluster running and accessible by other docker containers running on that machine.


Discussion

pic
Editor guide