Ideal setup of ECS cluster with Traefik and ALB

I currently have a cluster that uses Traefik as a reverse proxy. I love Traefik for the quick set up and service discovery, but am starting to hit some bumps that should really be handled by a load balancer. I have containers that work but will hang every now and then and report as unhealthy. I am not sure there is a way to restart the container in ECS without and ALB. If that is the case, does it even make sense to use Traefik?

I’d wait for other’s to chime in before taking my advice seriously, but I think you likely shouldn’t be using Traefik in ECS for basically these kinds of reasons. That’s not to say that there’s never a reason to use it, but I believe an ideal setup would have AWS managing basically every aspect of networking for you, which might make Traefik redundant.

I use Traefik all the time and I love it, but I haven’t seen any reason to use it with my various ECS setups. None of my projects do anything too fancy with networking, though, so I could imagine there might be some cases where Traefik could come into play. I’d suggest seeing if AWS can replace Traefik entirely in your setup first, and if you find a reason to not do this, then circle back around to see how you can solve this issue with Traefik.

If you really need treafic, maybe you can try aws service discovery. It can do healthcheck, but i don’t know if it can replace unhealthy task.

This was my thought. As it right now we kind of "daisy chain a local traefik server to the ECS instance. It would be quiet simple to just redirect the backend to a load balancer instead. I think what it is that I am just more comfortable with configuring traefik than a load balancer, especially with cloudformation/terraform.

use the alb. if you need it for header rewrites or gzipping (I don’t know trafik but I’m assuming it’s feature set is near nginx) then you could use the a sidecar container and proxy at the container level (there’s an ECS reverse proxy nginx example out there).

We had to use Traefik for a very specific edge case with the ALBs awhile back. Where possible, I would avoid it. ALBs are very robust now and they can do most things Traefik can. You lose a lot of benefits of the ALBs by circumventing then in the way you’re considering. ALBs are also protected by Shield and can have WAFs/GAs attached where as Traefik cannot.

That said, you should be able to use container health checks in your task definition to restart failed containers, even without an ALB.

I am not sure there is a way to restart the container in ECS without and ALB.

Mark the task as essential, then it will be replaced/restarted:

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

Task health is reported by the healthStatus of the task, which is determined by the health of the essential containers in the task. If all essential containers in the task are reporting as HEALTHY, then the task status also reports as HEALTHY. If any essential containers in the task are reporting as UNHEALTHY or UNKNOWN, then the task status also reports as UNHEALTHY or UNKNOWN, accordingly. If a service’s task reports as unhealthy, it is removed from a service and replaced.

ALB/target-group healtcheck is another failsafe where a container healtcheck might return healthy, but the ALB/target-group healtcheck fails it so it’s replaced that way.