Can NLB support mulitple target groups in one listener?

0

When building a network load balancer with the cloud formation, I got the following error:

  • you cannot specify multiple target groups in a single action with a load balancer of type 'network' I am adding two target groups in a single default action for a network listener, the part of cloud formation is at the bottom of the page.

If I create a NLB with 2 AZs, how can I add two target groups for 2 AZs into one listener of the NLB? I thought this would make the NLB fault-tolerant, but elastic load balancing doesn't allow this.

I have to work around this by adding targets in 2 AZs into one target group associating with the listener, but this will make load balancing cross the AZs which might cause higher latency and data transfer fees for NLB.

 NLB:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Name: !Sub "${NetworkStackName}-nlb"
      Scheme: "internet-facing"
      SecurityGroups: 
        - Fn::ImportValue: 
            'Fn::Sub': '${NetworkStackName}-PubSecurityGroupID'
      Subnets:
        - Fn::ImportValue: 
            'Fn::Sub': '${NetworkStackName}-PublicSubnetID-1'
        - Fn::ImportValue: 
            'Fn::Sub': '${NetworkStackName}-PublicSubnetID-2'    
      Tags:
      - Key: Name
        Value: !Sub "${NetworkStackName}-nlb"
      Type: "network"

  NLBListener1:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions: 
        - Type: forward
          ForwardConfig:
            TargetGroups: 
              - TargetGroupArn:
                  Fn::ImportValue: 
                    'Fn::Sub': '${NetworkStackName}-nlb-target-group-1'      
        - Type: forward
          ForwardConfig:
            TargetGroups: 
              - TargetGroupArn:
                  Fn::ImportValue: 
                    'Fn::Sub': '${NetworkStackName}-nlb-target-group-2'                                   
      LoadBalancerArn: !Ref NLB
      Port: 80
      Protocol: TCP
已提問 4 個月前檢視次數 249 次
1 個回答
1
已接受的答案

To achieve what your looking for is to add 2 targets in one target group on your listener and then disable cross zone load balancing.

When cross-zone load balancing is off, each load balancer node distributes traffic across only the registered targets in its Availability Zone.

profile picture
專家
已回答 4 個月前
profile picture
專家
已審閱 2 個月前
  • I might misunderstand the Target Group definition. I thought it was AZ-related but not. It seems a Target Group is just a virtual container including the targets from different AZs. Regarding the NLB, cross-zone load balancing is off by default, so the traffic is always routed to the targets in the same AZ.

    Is this a correct understanding?

  • You are correct with your understanding. A target group isn’t specific per AZ and multi AZ is disabled by default on a network load balancer.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南