codesuki / ecs-nginx-proxy

Reverse proxy for AWS ECS. Lets you address your docker containers by sub domain.
MIT License
98 stars 23 forks source link

Configuring Load Balancing #11

Open amlwwalker opened 7 years ago

amlwwalker commented 7 years ago

I've been using nginx-proxy for a while now, and came across this when wanting to move off vanilla ec2 and over to ecs. I've got it to a point where if I go directly to one of the 2 instances I am creating when I create a cluster (not both), I get the 'nginx is working' page. I have been writing down my understanding as following along, so will paste here:

First make a cluster

The name comes from the ecs config when you run ecs-cli configure...

ecs-cli up --keypair cluster-pair --capability-iam --size 2 --instance-type t2.small --force
Then we register the task that handles the proxy
aws ecs register-task-definition --cli-input-json file://./examples/task.json
Next we create a service, and connect up to the load balancer

(You need to have already created a load balancer)

aws ecs create-service --cluster ClusterName --role ecsServiceRole --load-balancers loadBalancerName=ECSLB,containerName=ecs-nginx-proxy,containerPort=80 --cli-input-json file://./examples/service.json

This tells the service that it should be accessible on port 80, the container is the ecs-nginx-proxy container, and the details are in service.json.

However when I configure the load balancer, and point it at my two instances that were created due to the above, going to its DNS address I get nothing back. Its only if I go directly to one of the instances.

Am I right in thinking that both sample_task and task are running on both instances and the load balancer is supposed to point to both instances? Thanks

codesuki commented 7 years ago

The service will register itself with the load balancer (adds listeners). Normally you don't need to change it's settings if I remember correctly. The load balancer needs the correct security privileges, i.e. access to the ECS instances.

In my case I run the service with "desiredCount": 1, so there is only one container with the ecs-nginx-proxy but you could increase that number and all the containers will register themselves with the load balancer.

If that doesn't help, let me know.