Docker Community Forums

Share and learn in the Docker community.

Struggling with Swarm load balancing on AWS

docker
aws

(Michael Wallett) #1

Hi,

Just getting going with swarm on AWS. I’m able to create my cluster with docker-machine, init swarm and spin up a service, but I’m struggling to get the load balancing working. I’m only able to curl the app on the hosts that it’s been deployed on, other hosts do not forward on requests, no round-robin going on. I’m using the following scripts to test my cluster. Any clues would be great, getting a bit stuck here.

#!/bin/bash

aws_region=eu-west-1
instances=6

n=1
while [ $n -le $instances ]
do
machine_name=$aws_region-$n
docker-machine create
–driver amazonec2
–amazonec2-region $aws_region
–amazonec2-security-group ‘swarm-cluster’
$machine_name &
n=$(( n + 1 ))
done

#!/bin/bash

Init managers

hostname=“eu-west-1-1"
echo $hostname
manager_ip=”$(docker-machine inspect $hostname | jq -r ‘.Driver.PrivateIPAddress’):2377"
docker $(docker-machine config $hostname) swarm init --advertise-addr $manager_ip --listen-addr $manager_ip

manager_token="$(docker $(docker-machine config $hostname) swarm join-token manager -q)“
worker_token=”$(docker $(docker-machine config $hostname) swarm join-token worker -q)"

hostname=“eu-west-1-2"
echo $hostname
ip=”$(docker-machine inspect $hostname | jq -r ‘.Driver.PrivateIPAddress’):2377"
docker $(docker-machine config $hostname) swarm join
–token $manager_token
$manager_ip
–advertise-addr $ip --listen-addr $ip

hostname=“eu-west-1-3"
echo $hostname
ip=”$(docker-machine inspect $hostname | jq -r ‘.Driver.PrivateIPAddress’):2377"
docker $(docker-machine config $hostname) swarm join
–token $manager_token
$manager_ip
–advertise-addr $ip --listen-addr $ip

Init workers

hostname=“eu-west-1-4"
echo $hostname
ip=”$(docker-machine inspect $hostname | jq -r ‘.Driver.PrivateIPAddress’):2377"
docker $(docker-machine config $hostname) swarm join
–token $worker_token
$manager_ip
–advertise-addr $ip --listen-addr $ip

hostname=“eu-west-1-5"
echo $hostname
ip=”$(docker-machine inspect $hostname | jq -r ‘.Driver.PrivateIPAddress’):2377"
docker $(docker-machine config $hostname) swarm join
–token $worker_token
$manager_ip
–advertise-addr $ip --listen-addr $ip

hostname=“eu-west-1-6"
echo $hostname
ip=”$(docker-machine inspect $hostname | jq -r ‘.Driver.PrivateIPAddress’):2377"
docker $(docker-machine config $hostname) swarm join
–token $worker_token
$manager_ip
–advertise-addr $ip --listen-addr $ip

eval $(docker-machine env eu-west-1-1)

docker service create --name web --replicas 3 --mount type=bind,src=/etc/hostname,dst=/usr/share/nginx/html/index.html,readonly --publish 80:80 nginx

You can see all the services running

docker service ls

You can see all web containers running

docker service ps web