What's the target group port for, when using Application Load Balancer + EC2 Container Service

后端 未结 4 1580
你的背包
你的背包 2021-02-01 15:02

I\'m trying to setup an ALB which listens on port 443, load balancing to ECS Docker containers on random ports, lets say I have 2 container instances of the same task definition

相关标签:
4条回答
  • 2021-02-01 15:39

    I ran into this situation myself at work. I noticed the target group port and the port of the registered instance were different. I've typically set them up to be the same thing so wondered what this was all about which led me to this thread. I couldn't find a good answer on AWS docs, but found this in the Terraform docs for aws_lb_target_group resource:

    port - (Optional, Forces new resource) The port on which targets receive traffic, unless overridden when registering a specific target.

    So, I guess it's just the default port used unless you override it. Makes sense.

    0 讨论(0)
  • 2021-02-01 15:40

    The port in the target group is used in conjunction with auto-scaling groups and if you ever plan to use those you want to use the right port from the start. Why? Because you can not change it after the target group has been created and auto-scaling will simply not work if you set the port wrong.

    0 讨论(0)
  • 2021-02-01 15:53

    I think what he's referring to is the health checks. If your ELB is listening on port 443 but your target group is set for port 80, then every health check for the target group will attempt a request on port 80 and get redirected to port 443 by the load balancer. This results in a 301 code, which is considered unhealthy. Only 200 codes are supposed to be considered healthy. At that point you either have all unhealthy targets all the time or you add 301 to the list of healthy codes which defeats the whole point in health checks because it will always return a 301 for port 80. You might as well just match the ports.

    0 讨论(0)
  • 2021-02-01 15:57

    Turns out, when combined with ECS, the target group's port doesn't mean anything. You don't need to listen on that port.

    0 讨论(0)
提交回复
热议问题