ECS Service Registers EC2 Instance more than desired In my ECS cluster using EC2 launch type

0

I had a previous problem with deploying my app on ECS using EC2 launch type and It Is now partially solved , I have deleted the entire cluster and created a new one again , and I have configured an ALB balancer and attached it to the service (I.e. this was not set up before) , I was using a t3.medium Instance which come with 2 vCPUs, 4GB Memory , I have set the Task Size to 1 vCPU and Memory to 3 GB (I.e. new revision of my task definition) and as I was planning to only run 1 container, In the Resource allocation limits section of the container, I set the CPU to 1 vCPU and Memory soft limit and hard limit to 1 and 3 respectively and It worked but another problem popped up. Initially while I was creating the new cluster , I didn't specify the min capacity I left It blank and I specified max capacity to 1 and then created the service. The problem Is In cloudformation, the service creation fail , but I in the cluster under services I can see that 1 task Is running and 1 task Is In provisioning status.

1-I don't understand why ECS Is trying to provision 2 tasks while I already specified In the task definition that I only need 1 task.

2-I can see In the ECS cluster infrastructure section , two container Instances registered one In active status and the other Is In draining status. why Is this happening ?

3-How the cloudformation stack for the ECS Service failed , while I have 1 task running on one Container Instance ?

Note:

1- I have suspended the ASG process and returned It back , but before I suspended the ASG process , It had the same behavior.

Task Definition :

{
    "family": "abc",
    "containerDefinitions": [
        {
            "name": "abc-container",
            "image": "<xyz>.dkr.ecr.<region>.amazonaws.com/abc-app:latest",
            "cpu": 1024,
            "memoryReservation": 1024,
            "portMappings": [
                {
                    "name": "abc",
                    "containerPort": 8080,
                    "hostPort": 8080,
                    "protocol": "tcp",
                    "appProtocol": "http"
                }
            ],
            "essential": true,
            "environment": [
                {
                    "name": "MYSQL_DATABASE",
                    "value": "..."
                },
                {
                    "name": "MYSQL_USERNAME",
                    "value": "..."
                },
                {
                    "name": "MYSQL_PASSWORD",
                    "value": "..."
                },
                {
                    "name": "MYSQL_PORT",
                    "value": "..."
                },
                {
                    "name": "MYSQL_HOST",
                    "value": "..."
                }
            ],
            "environmentFiles": [],
            "mountPoints": [],
            "volumesFrom": [],
            "ulimits": [],
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-create-group": "true",
                    "awslogs-group": "/ecs/my-app",
                    "awslogs-region": "<region>",
                    "awslogs-stream-prefix": "ecs"
                },
                "secretOptions": []
            },
            "systemControls": []
        }
    ],
    "taskRoleArn": "arn:aws:iam::<xyz>:role/ecsTaskExecutionRole",
    "executionRoleArn": "arn:aws:iam::<xyz>:role/ecsTaskExecutionRole",
    "networkMode": "awsvpc",
    "requiresCompatibilities": [
        "EC2"
    ],
    "cpu": "1024",
    "memory": "3072",
    "runtimePlatform": {
        "cpuArchitecture": "X86_64",
        "operatingSystemFamily": "LINUX"
    }
}

2- My related question https://repost.aws/questions/QUrrt5HgwfS4SvAyf1bXiNlw/unable-to-register-a-container-instance-with-ecs

1 Answer
1

hlo,

1.Provisioning 2 tasks instead of 1: This could be due to several reasons. Firstly, ensure that your service's desired count is set to 1. This parameter dictates how many tasks ECS should run. If it's set to 1 and you're still seeing 2 tasks, it could be due to a misconfiguration or an issue with the task definition. Double-check your task definition to ensure it's correctly specifying one container instance. Also, check if you have any scaling policies or rules in place that might be affecting the number of tasks.

2.Two container instances registered, one active and one draining: This behavior suggests that ECS is replacing the container instances, which could be due to scaling policies, instance health issues, or updates to the ECS cluster. The active instance is handling traffic, while the one in draining state is being removed from the cluster. Check your Auto Scaling Group (ASG) settings, instance health checks, and ECS cluster events for any clues.

3.CloudFormation stack failure despite one task running: The failure could be due to various reasons, such as resource constraints, conflicting configurations, or errors in the CloudFormation template. Check the CloudFormation stack events and logs for more details on why the stack creation failed. It's possible that the failure occurred during resource creation or updating the service.

Here are some steps you can take to troubleshoot these issues:

1.Review your ECS service configuration, including task definition, service settings (desired count, deployment configuration), and networking setup.

2.Check your Auto Scaling Group (ASG) configuration, instance health checks, and scaling policies to ensure they align with your desired ECS setup.

3.Examine ECS cluster events, CloudFormation stack events, and container instance logs for any error messages or warnings that might provide insights into the issues.

4.Consider reaching out to AWS support for assistance if you're unable to resolve the issues on your own.

answered 14 days 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