AWS上的Docker swarm负载平衡无法正常工作

时间:2016-10-13 18:46:10

标签: docker amazon-ec2 docker-swarm

刚开始使用AWS上的swarm。我能够使用docker-machine,init swarm创建我的集群并启动服务。但我努力让负载平衡工作

我只能在部署它的主机上卷曲应用程序,其他主机不会转发请求,也不会进行循环播放。

我正在使用以下脚本来测试我的群集。任何线索都会很棒,这里有点卡住了。

!/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

1 个答案:

答案 0 :(得分:0)

我在sa-east-1地区遇到了同样的问题。这个完全相同的群集配置在VirtualBox上的本地虚拟机中运行良好:

Client:
 Version:      1.13.0
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Tue Jan 17 09:58:26 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.0
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Tue Jan 17 09:58:26 2017
 OS/Arch:      linux/amd64
 Experimental: false