[英]how to deploy applications on docker swarm and expose that ip address to A record
I have successfully setup the docker swarm cluster with nginx. 我已经使用nginx成功设置了docker swarm集群。 on my ec2 instances.
在我的ec2实例上。 using this tutorial
使用本教程
https://botleg.com/stories/load-balancing-with-docker-swarm/ https://botleg.com/stories/load-balancing-with-docker-swarm/
I am using like this 我正在这样使用
Manager 1 经理1
node 1 节点1
node 2 节点2
I am using consol with registrator for service discovery. 我正在将consol与注册器一起用于服务发现。
In Consul Machine docker run --restart=unless-stopped -d -p 8500:8500 -h consul progrium/consul -server -bootstrap 在Consul Machine泊坞窗中运行--restart = unless-stopped -d -p 8500:8500 -h consul progrium / consul -server -bootstrap
Swarm Manager docker run --restart=unless-stopped -d -p 3375:2375 swarm manage --replication --advertise=mangerip:3375 consul://consulip:8500/ Swarm Manager泊坞窗运行--restart = unless-stopped -d -p 3375:2375 swarm管理--replication --advertise = mangerip:3375 consul:// consulip:8500 /
docker run --restart=unless-stopped -d --name=registrator -h=host --volume=/var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator:latest consul://consulip:8500 docker run --restart = unless-stopped -d --name = registrator -h = host --volume = / var / run / docker.sock:/tmp/docker.sock gliderlabs / registrator:latest consul:// consulip: 8500
Node1 docker run --restart=unless-stopped -d swarm join --advertise=node1ip:2375 consul://consulip:8500/ Node1泊坞窗运行--restart = unless-stopped -d swarm join --advertise = node1ip:2375 consul:// consulip:8500 /
docker run --restart=unless-stopped -d --name=registrator -h=host --volume=/var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator:latest consul://consulip:8500 docker run --restart = unless-stopped -d --name = registrator -h = host --volume = / var / run / docker.sock:/tmp/docker.sock gliderlabs / registrator:latest consul:// consulip: 8500
Node2 docker run --restart=unless-stopped -d swarm join --advertise=node2:2375 consul://consulip:8500/ Node2 Docker运行--restart = unless-stopped -d swarm join --advertise = node2:2375 consul:// consulip:8500 /
docker run --restart=unless-stopped -d --name=registrator -h=host --volume=/var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator:latest consul://consulip:8500 docker run --restart = unless-stopped -d --name = registrator -h = host --volume = / var / run / docker.sock:/tmp/docker.sock gliderlabs / registrator:latest consul:// consulip: 8500
my Dockerfile 我的Dockerfile
FROM nginx:latest
RUN apt-get update \
&& apt-get install -y unzip
ADD files/start.sh /bin/start.sh
RUN chmod +x /bin/start.sh
ADD files/default.ctmpl /templates/default.ctmpl
ADD https://releases.hashicorp.com/consul-template/0.12.2/consul-template_0.12.2_linux_amd64.zip /usr/bin/
RUN unzip /usr/bin/consul-template_0.12.2_linux_amd64.zip -d /usr/local/bin
EXPOSE 80
ENTRYPOINT ["/bin/start.sh"]
start.sh start.sh
#!/bin/bash
service nginx start
consul-template -consul=$CONSUL_URL -template="/templates/default.ctmpl:/etc/nginx/conf.d/default.conf:service nginx reload"
default.ctmpl default.ctmpl
{{$app := env "APP_NAME"}}
upstream {{printf $app}} {
least_conn;
{{range service $app}}
server {{.Address}}:{{.Port}} max_fails=3 fail_timeout=60 weight=1;{{end}}
}
server {
listen 80 default;
location / {
proxy_pass http://{{printf $app}};
}
}
docker-compose.yml docker-compose.yml
version: '2'
services:
lb:
build: .
container_name: lb
ports:
- "80:80"
environment:
- APP_NAME=tutum-nodejs-redis
- CONSUL_URL=${KV_IP}:8500
depends_on:
- web
networks:
- front-tier
web:
image: hanzel/tutum-nodejs-redis
ports:
- "4000"
environment:
- APP_PORT=4000
- REDIS_IP=redis
- REDIS_PORT=6379
depends_on:
- redis
networks:
- front-tier
- back-tier
redis:
image: redis
container_name: redis
command: redis-server --appendonly yes
volumes:
- redis-data:/data
networks:
- back-tier
volumes:
redis-data:
driver: local
networks:
front-tier:
driver: overlay
back-tier:
driver: overlay
The problem with this, Which Ip Address I need point to A record Since docker swarm picking node automatically. 问题是,我需要哪个IP地址指向A记录,因为docker swarm会自动选择节点。
lets say First time I am running this it may pick up the first node. 可以说我第一次运行它时,它可能会拾取第一个节点。 In case I am removing this and redoing althe steps that time it will pick different node and different ip.
万一我要删除此文件并重做所有步骤,那么它将选择不同的节点和不同的ip。 so that time I need to change my A record.
这样我就需要更改我的A记录。 Hw to solve this problem,
硬件解决这个问题,
I googled it , and I found the wagl. 我在Google上搜索了一下,然后找到了wagl。 that gives me DNS based service dicovery, that is cool.
这使我能够基于DNS进行服务发现,这很酷。 but it was very basic I guess , I dont know whether that was production ready or not.
但这是非常基本的,我不知道那是否已经准备好生产。
Please any one tell me, How to do from A to Z flow, ie, from the deployment to configuring the IP address to A record. 请任何人告诉我,如何执行从A到Z的流程,即从部署到将IP地址配置为A记录。 or just point me some link.
或只是给我一些链接。
I don't think you need to change you A record for that. 我认为您无需为此更改A记录。 Since you already know the ip addresses of your cluster, and if you are deploying it using
docker-compose
you can add a constraint
on your load-balancer environment: constraint:node==node1
由于您已经知道集群的IP地址,并且如果您正在使用
docker-compose
进行部署,则可以在负载均衡器环境中添加一个constraint
: constraint:node==node1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.