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
preguntada hace un año1 mil visualizaciones
1 Respuesta
1
Respuesta aceptada

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
EXPERTO
respondido hace un año
profile picture
EXPERTO
revisado hace 10 meses
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas