简体   繁体   English

在 AWS ECS 中设置服务的问题

[英]Problem with setting a service in AWS ECS

I was trying to set up a ECS service running a container image on a cluster, but could not get the setup working.我试图在集群上设置运行容器映像的 ECS 服务,但无法使设置正常工作。

I have basically followed the guide on https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-blue-green.html , except that I was trying to host the containers on EC2 instances.我基本上遵循了https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-blue-green.html上的指南,只是我试图在 EC2 实例上托管容器。

I wonder if the issue is related to the network mode (used "awsvpc").我想知道问题是否与网络模式(使用“awsvpc”)有关。

Expectation期待

It should show something on index.html on access witht eh ALB link它应该在使用 eh ALB 链接访问时在 index.html 上显示一些内容

Observation观察

When I tried to access with the load balancer link, it gives HTTP 503, and the health-check also showed unhealthy当我尝试使用负载均衡器链接访问时,它给出了 HTTP 503,并且健康检查也显示不健康

ALB_Link_HTTP_503

And it seems ECS keeps "re-creating" the conatiners?而且似乎 ECS 一直在“重新创建”容器? (Forgive me as I am still not familiar with ECS) (原谅我对ECS还不熟悉)

Containers_keep_re-creating

Tried to access the container instance directly but also could not reach试图直接访问容器实例但也无法访问

Container_instance_link

Conatiner_instance_could_not_reach

I had a look on the ECS agent log (/var/logs/ecs-agent.log) on the container instance, the image should have been pulled sucessfully我查看了容器实例上的 ECS 代理日志(/var/logs/ecs-agent.log),应该已成功拉取镜像

Image_pulled_successfully

And the task should have been started而且任务应该已经开始了

在此处输入图片说明

ECS service events ECS服务事件

It seems it kept register and deregister target似乎它保持注册和注销目标

ECS_service_events

Security groups have been set to accept HTTP traffic安全组已设置为接受 HTTP 流量

Setup设置

Tomcat server on container starts on port 80容器上的 Tomcat 服务器在端口 80 上启动

  • ALB ALB

在此处输入图片说明

  • Listener听众

在此处输入图片说明

  • Target group目标组

在此处输入图片说明

ECS task definition creation ECS 任务定义创建

{
"family": "TestTaskDefinition",
"networkMode": "awsvpc",
"containerDefinitions": [
    {
        "name": "TestContainer",
        "image": "<Image URI>",
        "portMappings": [
            {
                "containerPort": 80,
                "hostPort": 80,
                "protocol": "tcp"
            }
        ],
        "essential": true
    }
],
"requiresCompatibilities": [
    "EC2"
],
"cpu": "256",
"memory": "512",
"executionRoleArn": "<ECS execution role ARN>"
}

ECS service creation ECS服务创建

{
"cluster": "TestCluster",
"serviceName": "TestService",
"taskDefinition": "TestTaskDefinition",
"loadBalancers": [
    {
        "targetGroupArn": "<target group ARN>",
        "containerName": "TestContainer",
        "containerPort": 80
    }
],
"launchType": "EC2",
"schedulingStrategy": "REPLICA",
"deploymentController": {
    "type": "CODE_DEPLOY"
},
"networkConfiguration": {
   "awsvpcConfiguration": {
      "assignPublicIp": "DISABLED",
      "securityGroups": [ "sg-0f9b629686ca3bd08" ],
      "subnets": [ "subnet-05f47b367df4f50d4", "subnet-0fd76fc8e47ea3be7" ]
   }
},
"desiredCount": 1
}

Based on the comments.根据评论。

To investigate the issue, it was recommended to tested the ECS service without ALB.为了调查该问题,建议在没有 ALB 的情况下测试 ECS 服务。 Based on the test, it was found that the ALB was treating the ECS service as unhealthy due to long application starting time .根据测试发现,由于应用程序启动时间过长,ALB 将 ECS 服务视为不健康。

The issue was solved by increasing ALB health-check grace period to (eg 300s).该问题已通过将 ALB 运行状况检查宽限期增加到(例如 300 秒)来解决。

not sure if EC2 launch type must use "bridge"不确定 EC2 启动类型是否必须使用“桥接”

You can use awsvpc on EC2 instances as well, but bridge is easier to use in this case.您也可以在 EC2 实例上使用awsvpc ,但在这种情况下bridge更容易使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM