Home > Software engineering >  Network load balancer never becomes healthy
Network load balancer never becomes healthy

Time:02-01

I am trying to host a service on Fargate that exposes a TCP port. Even this simple example that exposes HTTP on port 80 never becomes healthy on Fargate.

var loadBalancedFargateService = NetworkLoadBalancedFargateService.Builder.create(this, "ServiceSample")
        .cluster(fargateCluster)
        .publicLoadBalancer(true)
        .memoryLimitMiB(1024)
        .cpu(512)
        .listenerPort(80)
        .taskImageOptions(NetworkLoadBalancedTaskImageOptions.builder()
                .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
                .containerPort(80)
                .build())
        .build();

The error I get is:

service dev-shopapi-redis-ServiceSampleService16E525F0-ASe7w3oUlGf9 port 80 is unhealthy in target-group dev-sh-Servi-EFOUJ7LG0YPP  due to (reason Health checks failed).

My intention is to expose another service with a TCP protocol and this is a simplified version that exposes HTTP.

What I am doing wrong?

CodePudding user response:

Try these troubleshooting steps:

  • If your container is mapped to port 80, confirm that your container security group allows inbound traffic on port 80 for the load balancer.
  • Confirm that the ping port value for your load balancer health is configured correctly. If this port isn't configured correctly, then your load balancer could de-register the container from itself.
  • Define a minimum health check grace period. This instructs the service scheduler to ignore Elastic Load Balancing health checks for a pre-defined time period after a task has been instantiated.
  • Monitor the CPU and memory metrics of the service. For example, high CPU can make your application unresponsive and result in a 502 error.
  • Check your application logs for application errors.
  • Check if the ping port and the health check path are configured correctly.

Unlike the ApplicationLoadBalancedFargateService, the NetworkLoadBalancedFargateService does not automatically configure the container port.

So just add the following in the CDK:

loadBalancedEcsService.getService().getConnections().allowFromAnyIpv4( Port.tcp(80) );//80 since the container is listening on port 80

Source: https://aws.amazon.com/premiumsupport/knowledge-center/ecs-fargate-health-check-failures/

  • Related