Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How configure health check for containers deployed to AWS ECS

I am currently working with AWS ECS and I'm a little confused on how you should configure the health check for containers deployed to AWS ECS.

You can define the healthcheck on the TargetGroup but you can also define the health check on the TaskDefinition.

I wanted to know what is best practice and why. Currently I have defined it in the TargetGroup and it works as expected.

But I wanted clarity on why you would use one over the other? And would you ever define it in both places?

I am using an Application Load Balancer with ECS.

like image 572
LittleBigUllah Avatar asked Nov 14 '19 17:11

LittleBigUllah


People also ask

How do you check the health of a container?

We can also see the health status by running docker ps. Notice under STATUS, the status is Up with (healthy) next to it. The health status appears only when a health check is configured.

What are health checks in AWS?

Health checks are a way of asking a service on a particular server whether or not it is capable of performing work successfully. Load balancers ask each server this question periodically to determine which servers it is safe to direct traffic to.

How do ECS communicate between containers?

The link parameter allows containers to communicate with each other without the need for port mappings. Only supported if the network mode of a task definition is set to bridge. The name:internalName construct is analogous to name:alias in Docker links.


1 Answers

You should use health check in ALB if you are using ALB.

If ALB check failed, ALB will make target group unhealthy and as a result, your container will be killed.

The most important in health check is the HTTP status code, it should be 200 or 3xx or 4xx depend on configuration. if the specified code does not match target will be marked unhealthy.

Both checks has difference purpose,

  • If you are using ALB, you should use ALB healthcheck
  • If you are using scheduler base Task, then you can use Docker container health checks.

Amazon Elastic Container Service (ECS) now supports Docker container health checks. This gives you more control over monitoring the health of your tasks and improves the ability of the ECS service scheduler to ensure your services are healthy.

Previously, the ECS service scheduler relied on the Elastic Load Balancer (ELB) to report container health status and to restart unhealthy containers. This required you to configure your ECS Service to use a load balancer, and only supported HTTP and TCP health-checks.

ecs-supports-container-health-checks-and-task-health-mana

If a service's task fails the load balancer health check criteria, the task is stopped and restarted. This process continues until your service reaches the number of desired running tasks.

service-load-balancing-health

like image 106
Adiii Avatar answered Sep 28 '22 02:09

Adiii