gpt4 book ai didi

amazon-web-services - AWS ECS Fargate 容器运行状况检查命令

转载 作者:行者123 更新时间:2023-12-04 12:38:52 25 4
gpt4 key购买 nike

我正在尝试设置 aws ecs fargate 部署配置。我能够在没有容器健康检查的情况下运行容器。但是,我也想运行容器健康检查。我尝试了所有可能的方案来实现这一点。但是,没有运气。

Container Health Check Command

我尝试使用以下 aws 推荐的命令来验证来自列出的 url 的容器运行状况检查。

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_healthcheck

  • [ "CMD-SHELL", "curl -f http://localhost/ || 退出 1"]
  • [ "CMD-SHELL""curl -f 127.0.0.1 || 退出 1"]

  • 我尝试了以上两个命令。但是,它们都没有按预期工作。请帮我接收容器有效的健康检查命令

    下面是我的 DockerFile
        FROM centos:latest
    RUN yum update -y
    RUN yum install httpd httpd-tools curl -y
    EXPOSE 80
    CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
    HEALTHCHECK CMD curl --fail http://localhost:80/ || exit 1
    FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
    WORKDIR /app
    EXPOSE 80
    FROM microsoft/dotnet:2.1-sdk AS build
    WORKDIR /DockerDemoApi
    COPY ./DockerDemoApi.csproj DockerDemoApi/
    RUN dotnet restore DockerDemoApi/DockerDemoApi.csproj
    COPY . .
    WORKDIR /DockerDemoApi
    RUN dotnet build DockerDemoApi.csproj -c Release -o /app
    FROM build AS publish
    RUN dotnet publish DockerDemoApi.csproj -c Release -o /app
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "DockerDemoApi.dll"]

    我在我的容器中添加了 curl 命令及其工作。但是,如果我在 AWS Healthcheck 任务中保留相同的命令,它就会失败。

    任务定义 JSON:
        {
    "ipcMode": null,
    "executionRoleArn": "arn:aws:iam::xxxx:role/ecsTaskExecutionRole",
    "containerDefinitions": [{
    "dnsSearchDomains": null,
    "logConfiguration": {
    "logDriver": "awslogs",
    "secretOptions": null,
    "options": {
    "awslogs-group": "/ecs/mall-health-check-task",
    "awslogs-region": "ap-south-1",
    "awslogs-stream-prefix": "ecs"
    }
    },
    "entryPoint": [],
    "portMappings": [
    {
    "hostPort": 80,
    "protocol": "tcp",
    "containerPort": 80
    }
    ],
    "command": [],
    "linuxParameters": null,
    "cpu": 256,
    "environment": [],
    "resourceRequirements": null,
    "ulimits": null,
    "dnsServers": null,
    "mountPoints": [],
    "workingDirectory": null,
    "secrets": null,
    "dockerSecurityOptions": null,
    "memory": null,
    "memoryReservation": 512,
    "volumesFrom": [],
    "stopTimeout": null,
    "image": "xxxx.dkr.ecr.ap-south-
    1.amazonaws.com/autoaml/api/dev/alpine:latest",
    "startTimeout": null,
    "dependsOn": null,
    "disableNetworking": null,
    "interactive": null,
    "healthCheck": null,
    "essential": true,
    "links": [],
    "hostname": null,
    "extraHosts": null,
    "pseudoTerminal": null,
    "user": null,
    "readonlyRootFilesystem": null,
    "dockerLabels": null,
    "systemControls": null,
    "privileged": null,
    "name": "sample-app"
    }
    ],
    "placementConstraints": [],
    "memory": "512",
    "taskRoleArn": "arn:aws:iam::xxxx:role/ecsTaskExecutionRole",
    "compatibilities": [
    "EC2",
    "FARGATE"
    ],
    "taskDefinitionArn": "arn:aws:ecs:ap-south-1:xxx:task-definition/mall-
    health-check-task:9",
    "family": "mall-health-check-task",
    "requiresAttributes": [{
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "ecs.capability.execution-role-ecr-pull"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "ecs.capability.task-eni"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "com.amazonaws.ecs.capability.ecr-auth"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "com.amazonaws.ecs.capability.task-iam-role"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "ecs.capability.execution-role-awslogs"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
    },
    {
    "targetId": null,
    "targetType": null,
    "value": null,
    "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
    }
    ],
    "pidMode": null,
    "requiresCompatibilities": [
    "FARGATE"
    ],
    "networkMode": "awsvpc",
    "cpu": "256",
    "revision": 9,
    "status": "ACTIVE",
    "proxyConfiguration": null,
    "volumes": []
    }

    最佳答案

    Documentation提到以下内容:

    When registering a task definition in the AWS Management Console, use a comma separated list of commands which will automatically converted to a string after the task definition is created. An example input for a health check could be:

    CMD-SHELL, curl -f http://localhost/ || exit 1

    When registering a task definition using the AWS Management Console JSON panel, the AWS CLI, or the APIs, you should enclose the list of commands in brackets. An example input for a health check could be:

    [ "CMD-SHELL", "curl -f http://localhost/ || exit 1" ]



    enter image description here

    您是否验证了您的健康检查命令?我的意思是, http://127.0.0.0是有效的,对吗?
    当您点击 http://127.0.0.0 时,检查您的容器是否返回成功响应(无端口)。

    下面是示例任务定义。这是在容器中启动 tomcat 服务器并检查运行状况 (localhost:8080)
  • 根据需要修改任务定义(如 Role Arn )
  • 创建 ECS 服务并映射任务定义。
  • 创建配置的日志组。
  • 启动 ECS 服务,您的任务应显示为“健康”。
  • {
    "ipcMode": null,
    "executionRoleArn": "arn:aws:iam::accountid:role/taskExecutionRole",
    "containerDefinitions": [
    {
    "dnsSearchDomains": null,
    "logConfiguration": {
    "logDriver": "awslogs",
    "secretOptions": null,
    "options": {
    "awslogs-group": "/test/test-task",
    "awslogs-region": "us-east-2",
    "awslogs-stream-prefix": "test"
    }
    },
    "entryPoint": null,
    "portMappings": [
    {
    "hostPort": 8080,
    "protocol": "tcp",
    "containerPort": 8080
    }
    ],
    "command": null,
    "linuxParameters": null,
    "cpu": 0,
    "environment": [],
    "resourceRequirements": null,
    "ulimits": null,
    "dnsServers": null,
    "mountPoints": [],
    "workingDirectory": null,
    "secrets": null,
    "dockerSecurityOptions": null,
    "memory": null,
    "memoryReservation": null,
    "volumesFrom": [],
    "stopTimeout": null,
    "image": "tomcat",
    "startTimeout": null,
    "dependsOn": null,
    "disableNetworking": false,
    "interactive": null,
    "healthCheck": {
    "retries": 3,
    "command": [
    "CMD-SHELL",
    "curl -f http://localhost:8080/ || exit 1"
    ],
    "timeout": 5,
    "interval": 30,
    "startPeriod": null
    },
    "essential": true,
    "links": null,
    "hostname": null,
    "extraHosts": null,
    "pseudoTerminal": null,
    "user": null,
    "readonlyRootFilesystem": null,
    "dockerLabels": null,
    "systemControls": null,
    "privileged": null,
    "name": "tomcat"
    }
    ],
    "memory": "1024",
    "taskRoleArn": "arn:aws:iam::accountid:role/taskExecutionRole",
    "family": "test-task",
    "pidMode": null,
    "requiresCompatibilities": [
    "FARGATE"
    ],
    "networkMode": "awsvpc",
    "cpu": "512",
    "proxyConfiguration": null,
    "volumes": []
    }

    关于amazon-web-services - AWS ECS Fargate 容器运行状况检查命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56607995/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com