service "service-name" port 80 is unhealthy in target-group "target-group" due to (reason Health checks failed with these codes: [502]).

0

I am trying to deploy a docker image in a AWS ECS with Fargate task using AWS CDK. I have previously done the same thing using the console, and have replicated to configuration in CDK. When I try to deploy the service shows that the task continues to start and stop my task and register and deregister the target in my target group and says: service "service-name" port 80 is unhealthy in target-group "target-group" due to (reason Health checks failed with these codes: [502]).

My target group has the following properties: Target type: IP, Protocol HTTP:80, Protocol version: HTTP1, IP address type: IPv4

In my CDK code I specify targets: [new IpTarget('172.31.33.49')]. It looks like this target is created and then the health status is 'unhealthy' and other registered targets with IP address 172.31.87.112 and 172.31.72.34 are created which I don't understand.

Could someone help me to troubleshoot these issues?

3 Answers
0

I have gone through the bullet points on the article. Everything looks to be configured properly but in regards to this bulletpoint:

  • Monitor the CPU and memory metrics of the service. For example, high CPU can make your application unresponsive and result in a 502 error.

What is considered high CPU? It appears that my CPU utilization starts off at very close to 100% before crashing. Could this be the issue and how can it be resolved?

Enter image description here

AWS
answered 10 months ago
  • Can you confirm cpu/mem requirements of containers?Increasing CPU limit of task if it is possible.

0

Thanks. I increased the CPU/Memory to 4 vCPU/8 GB (previously 2 vCPU/4 GB) but the CPU utilization graph still looks the same and am having the same issue. I originally used 2 vCPU/4 GB because the documentation from Appsmith (the image I am trying to launch in my task) (https://docs.appsmith.com/getting-started/setup/installation-guides/aws-ecs-on-fargate) specified this in the deployment instructions.

AWS
answered 10 months ago
  • Hmm..It seems its not resource issue. So my additional question is as follows.

    · Can't you find containers launch successfuly from container logs? · Where 172.31.33.49 comes from? Tasks IP?Doesn't it change when task recreated?When I wrote cdk code about fargate I used service.attachToApplicationTargetGroup to specify target so specifying ip address is not needed.

    // Target Group
    const targetGroup = new elbv2.ApplicationTargetGroup(this, 'TargetGroup', {
          vpc,
          port: 80,
          protocol: elbv2.ApplicationProtocol.HTTP,
          targetType: elbv2.TargetType.IP,
          healthCheck: {
            path: '/',
            interval: Duration.seconds(60),
            healthyHttpCodes: '200'
          },
        })
    
     listener.addTargetGroups('TargetGroup', {
       targetGroups: [targetGroup],
     })
    
    const service = new ecs.Ec2Service(this, 'Service', {
          cluster,
          taskDefinition,
          securityGroups: [securityGroupAPP],
        })
        service.attachToApplicationTargetGroup(targetGroup)
      }
    
0
profile picture
EXPERT
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions