Skip to content

Commit

Permalink
add docker swarm tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Dec 18, 2018
1 parent d8ebaa1 commit b2993bc
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,86 @@ Detailed run output will be emitted when using the LinodeGo `LINODE_DEBUG=1` opt
LINODE_DEBUG=1 docker-machine --debug create -d linode --linode-token=$LINODE_TOKEN --linode-root-pass=$ROOT_PASS machinename
```

## Provisioning Docker Swarm

Let's create a docker swarm with master and worker node using private networking. Before starting make sure you have `docker-machine` and `jq` installed.

1. Create install.sh bash script and replace LINODE_TOKEN with your actual linode access token.
```sh
#!/bin/bash
set -e

LINODE_TOKEN=<YOUR LINODE TOKEN>
LINODE_ROOT_PASSWORD=$(openssl rand -base64 32); echo Password for root: $LINODE_ROOT_PASSWORD
LINODE_REGION=eu-central

create_node() {
local name=$1
docker-machine create \
-d linode \
--linode-label=$name \
--linode-instance-type=g6-nanode-1 \
--linode-image=linode/ubuntu18.04 \
--linode-region=$LINODE_REGION \
--linode-token=$LINODE_TOKEN \
--linode-root-pass=$LINODE_ROOT_PASSWORD \
--linode-create-private-ip \
$name
}

get_private_ip() {
local name=$1
echo $(docker-machine inspect $name | jq -r '.Driver.PrivateIPAddress')
}

init_swarm_master() {
local name=$1
local ip=$(get_private_ip $name)
docker-machine ssh $name "docker swarm init --advertise-addr ${ip}"
}

init_swarm_worker() {
local master_name=$1
local worker_name=$2
local master_addr=$(get_private_ip $master_name):2377
local join_token=$(docker-machine ssh $master_name "docker swarm \join-token worker -q")
docker-machine ssh $worker_name "docker swarm join --token=${join_token} ${master_addr}"
}

# create master node
create_node master01

# create worker node
create_node worker01

# init swarm master
init_swarm_master master01

# init swarm worker
init_swarm_worker master01 worker01
```

2. After provision is successful check docker swarm status.

```sh
docker-machine ssh master01 "docker node ls"
```

Output should show active swarm leader and worker.

```
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
f8x7zutegt2dn1imeiw56v9hc * master01 Ready Active Leader 18.09.0
ja8b3ut6uaivz5hf98gah469y worker01 Ready Active 18.09.0
```

3. Cleanup resources

```sh
docker-machine rm worker01 -y
docker-machine rm master01 -y
```

## Discussion / Help

Join us at [#linodego](https://gophers.slack.com/messages/CAG93EB2S) on the [gophers slack](https://gophers.slack.com)
Expand Down

0 comments on commit b2993bc

Please sign in to comment.