LoadBalancer health check fails but instance is not terminating

0

Hello,

I have a load balancer which as you know keeps the health check for the web app/website.

I have deployed nothing in my instance means no app/site so when anyone visits the Loadbalancer URL they see a 502 Bad gateway error which is fine.

and also in the target group, it shows that an instance has failed the health check but the thing is that the auto-scaling group is not terminating the failed health check instance and replacing it.

Below is the Cloudformation code

AutoScailingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      VPCZoneIdentifier:
       - Fn::ImportValue: !Sub ${EnvironmentName}-PR1
       - Fn::ImportValue: !Sub ${EnvironmentName}-PR2
      LaunchConfigurationName: !Ref AppLaunchConfiguration
      MinSize: 1
      MaxSize: 4
      TargetGroupARNs: 
        - Ref: WebAppTargetGroup

  AppLoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      SecurityGroups:
        - Ref: ApplicationLoadBalancerSecurityGroup
      Subnets:
       - Fn::ImportValue: !Sub ${EnvironmentName}-PU1
       - Fn::ImportValue: !Sub ${EnvironmentName}-PU2
      Tags:
       - Key: Name
         Value: !Ref EnvironmentName

  Listener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    Properties:
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref WebAppTargetGroup
      
      LoadBalancerArn: !Ref AppLoadBalancer
      Port: "80"
      Protocol: HTTP

  LoadBalancerListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      Actions:
      - Type: forward
        TargetGroupArn: !Ref WebAppTargetGroup
      Conditions:
      - Field: path-pattern
        Values: [/]
      ListenerArn: !Ref Listener
      Priority: 1

  WebAppTargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      HealthCheckIntervalSeconds: 10
      HealthCheckPath: /
      HealthCheckProtocol: HTTP
      HealthCheckTimeoutSeconds: 8
      HealthyThresholdCount: 2
      Port: 80
      Protocol: HTTP
      UnhealthyThresholdCount: 5
      VpcId:
        Fn::ImportValue:
            Fn::Sub: "${EnvironmentName}-VPCID"

  
  

  

1개 답변
1
수락된 답변

Is this a new stack (aka, it wasn't working with healthy instances before)? If so, then the target group won't be in the InService state, meaning the ASG won't ever mark an instance unhealthy for failing ELB healthchecks for that target group. AutoScaling does this to prevent an infinite launch/terminate loop

https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeLoadBalancerTargetGroups.html

Once that ASG has seen a single instance has ever been healthy on that target group, it will move the target group from the Added state to the InService state and replacements will happen like normal.

I've send some documentation feedback to the AutoScaling team to get this information added to the ELB Healthcheck for AutoScaling docs instead of just existing in the API docs like it currently does.

AWS
답변함 2년 전
  • Wow. Never thought in this way regarding Target group States. Thanks man!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠