containers-roadmap icon indicating copy to clipboard operation
containers-roadmap copied to clipboard

[ECS,Fargate] Multiple target groups for a service

Open zaitsman opened this issue 8 years ago • 86 comments

Summary

I want to be able to route traffic from two different Path rules in my ALB to the same ECS instance and have ECS automatically register targets in both groups.

Description

Pretty much what the summary says. I can manually add targets to the second group, but if the service is restarted, then the second group loses the targets

Expected Behavior

Unable to have 2 targets for the same ECS service

Observed Behavior

N/A

Environment Details

Supporting Log Snippets

zaitsman avatar Apr 17 '18 13:04 zaitsman

hey @zaitsman, ECS service team member here.

We don't currently support multiple target groups per service today. However, if you're able to use the same port on the same ALB you can re-use the same target group for multiple rules on a single loadbalancer.

dastbe avatar Apr 23 '18 19:04 dastbe

@dastbe I do use that, actually, but my use case is that i want the same container to respond to two different TG's for different ALB's. I understand that is a feature request. One way to solve it would be if we could get a Cloudwatch alarm each time ECS registers something, we could then lambda those additional registrations.

alexzaytsev-newsroomly avatar Apr 24 '18 00:04 alexzaytsev-newsroomly

One way to solve it would be if we could get a Cloudwatch alarm each time ECS registers something

@alexzaytsev-newsroomly, have you looked at the ECS event stream? There are container instance registration/deregistration that are surfaced through CloudWatch events. Let us know if this captures your specific use case.

adnxn avatar Apr 24 '18 15:04 adnxn

@dastbe does we have Multiple target groups for ECS service support in Fargate mode?

hridyeshpant avatar Apr 27 '18 07:04 hridyeshpant

Is multiple target groups per ECS service feature going to happen? On the roadmap?

bataras avatar May 30 '18 17:05 bataras

I need this feature too. Our application inside a container listens on 3 different ports for different purposes but I'm able to (automatically) register container only in one target group

DenisBY avatar Jun 15 '18 14:06 DenisBY

We could also really use this as well. We've reached the maximum number of certificates per load balancer and need a way to add the service to additional load balancers without creating a duplicate service.

Raizex avatar Jul 02 '18 22:07 Raizex

I could use this as well. We would like to put up a single Fargate ECS service with several containers each providing a different branch of the code running on a different port for our product and QA teams to use.

sergedomk avatar Jul 03 '18 00:07 sergedomk

This is a blocking issue for me. I have one primary service and one secondary service. The primary receives traffic for /management route. The primary and secondary both receive traffic for all other routes *. This pattern is impossible to implement without the ability to register 2 target groups for the primary instance.

This is the pattern currently used by Prisma as described here: https://github.com/prismagraphql/prisma/issues/2850#issuecomment-409868271

mcmar avatar Aug 12 '18 22:08 mcmar

I solved an issue by pointing current instances in stack, but it will not works with auto scaling. The feature will be useful.

zymtx5g79k avatar Aug 21 '18 12:08 zymtx5g79k

@zymtx5g79k Can you clarify what you mean by pointing current instances in stack? I'd love to get a solution to this and I'm not currently using autoscaling. Does your solution work with ECS on Fargate?

mcmar avatar Aug 22 '18 00:08 mcmar

@mcmar, hello:

EC2 -> Target groups -> Create target group -> Target type (instance) -> Create.
Select just created target group -> Actions -> Register and deregister targets -> Check all Instances that work in your stack -> Add to registered -> Save.

After some time the target group will detect which an instance has your service and will mark it as healthy. Load balancer will redirect traffic on the healthy instance.

In my case: it slanger service. Port 4567 was assigned in ECS service and port 8080 (websocket) is listen from all instances.

Tip: Target group need some time to correct healthy status after ECS service migration across EC2 instances. You can get connections refused until new healthy instances was found.

In my case: websocket connections will be repeated. It is regular case for frontend. I use EC2 stack "because I can"! (:

zymtx5g79k avatar Aug 22 '18 03:08 zymtx5g79k

I could use this too.

In my use case, we have one legacy application running behind an Application load balancer but rather than rebuild the whole application from scratch, we can go down the route of rebuilding pieces and just forwarding from the first Application Load Balancer to a new target group (listener rules). Unfortunately when using Fargate/ECS it owns the registrations for the Target Group and a target group can only be associated with 1 Load Balancer (which Fargate/ECS owns). So we are left with trying to figure out a way to mirror that Target Group when we get new ECS Registrations.

theladyjaye avatar Sep 01 '18 07:09 theladyjaye

another use case would be something that exposes multiple ports (like, say, rabbitmq's 5672 (AMQP) + 1567 (management UI)); since network load balancers seem to force traffic to the target group port instead of keeping the listener port, one needs to have a target group for each port, but only one of them ever gets updated by ECS

m0n5t3r avatar Sep 11 '18 09:09 m0n5t3r

This is a blocker - we require to have an option to register more than single port for our services.

hajdukd avatar Sep 12 '18 09:09 hajdukd

@hajdukd I hate to see you blocked by this. Per one of the comments above:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html

Using ECS Event Streams via CloudWatch events and triggering a Lambda definitely is a solution that works. It’s not as convenient if they offered it automatically, but you can add and remove from as many target groups as you want. So for a small bit of extra work (1 Lambda function and some event wiring) you will be unblocked.

theladyjaye avatar Sep 12 '18 12:09 theladyjaye

Nathan Peck from ECS product team has recommended a few very useful options: https://gist.github.com/nathanpeck/a8537e21627b3a0f3e735eecbe6f6384

renuez avatar Sep 26 '18 12:09 renuez

Thanks everyone for the feedback on this issue. I wanted to let you know that we on the ECS team are aware of it, and are actively considering solutions. +1's and additional details on use cases are always appreciated and will help inform our work moving forward.

coultn avatar Oct 31 '18 20:10 coultn

+1

cnelson avatar Nov 01 '18 18:11 cnelson

+1

davidfti avatar Nov 02 '18 21:11 davidfti