AWS Fargate 任务维护常见问题解答 - Amazon Elastic Container Service

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS Fargate 任务维护常见问题解答

什么是 Fargate 任务维护和退役?

AWS 负责维护 AWS Fargate 的底层基础架构。 AWS 确定何时需要将平台版本修订版替换为新修订版。这就是所谓的任务退休。 AWS 当平台版本版本停用时,会发送任务停用通知。我们会定期更新支持的平台版本以引入新版本,其中包含对 Fargate 运行时软件的更新以及操作系统和容器运行时等底层依赖项。更新版本发布后,我们会停用旧版本,以确保所有客户工作负载均在 Fargate 平台版本的最新版本上运行。当停用修订版时,系统会停用在该修订版上运行的所有任务。

Amazon ECS 任务可以分为服务任务和独立任务。服务任务作为服务的一部分进行部署,并由 Amazon ECS 计划进行控制。有关更多信息,请参阅 Amazon ECS 服务。独立任务是由 Amazon ECS RunTask API 直接启动的任务,也可以由外部计划程序启动,例如计划任务(由 Amazon 启动 EventBridge) AWS Batch、或 AWS Step Functions。

对于服务任务,除非您想先 AWS 替换这些任务,否则无需执行任何操作。当 Amazon ECS 计划程序停止任务时,它会使用最低的运行状况百分比并启动一个新任务,尝试保持所需的服务计数。默认情况下,服务的最小正常百分比为 100%,因此在停止任务之前应先启动新任务。在扩展服务、部署配置更改或部署任务定义修订时,通常会以相同的方式替换服务任务。为了准备任务停用过程,我们建议通过模拟此场景来测试您的应用程序行为。通过停止您的服务中的单个任务来测试复原能力,可以实现此目的。

对于独立任务 AWS 停用,在任务停用日期当天或之后停止任务。当任务停止时,我们不会启动替换任务。如果您需要这些任务继续运行,则需要在通知中指定的时间之前停止正在运行的任务并启动替换任务。因此,我们建议客户监控独立任务的状态,并在需要时实施逻辑来替换已停止的任务。

在任何情景中停止任务时,您都可以运行 describe-tasks。响应中的 stoppedReasonECS is performing maintenance on the underlying infrastructure hosting the task

任务停用通知中有什么?

任务停用通知通过 AWS Health 控制面板以及通过电子邮件发送到注册的电子邮件地址,其中包含以下信息:

  • 任务停用日期 - 任务在此日期或之后停止。

  • 对于独立任务,任务的 ID。

  • 对于服务任务,运行服务的集群 ID 和服务 ID。

  • 您需要采取的后续步骤。

通常,我们会针对每个任务中的服务和独立任务各发送一条通知 AWS 区域。但是,在某些情况下,每种任务类型可能会收到多个事件,例如,当有太多任务需要停用时,这些任务将超过我们通知机制的限制。

通过以下方式,您可以确定计划停用的任务:

  • 的 AWS Health Dashboard

    AWS Health 通知可以通过 Amazon 发送 EventBridge 到存档存储(例如亚马逊简单存储服务)、执行自动操作(例如运行 AWS Lambda 函数)或其他通知系统(例如亚马逊简单通知服务)。有关更多信息,请参阅使用 Amazon 监控 AWS Health 事件 EventBridge。有关向 Amazon Chime、Slack 或 Microsoft Teams 发送通知的示例配置,请参阅上的 A AWS Health w are 存储库。 GitHub

    以下是一个示例 EventBridge 事件。

    { "version": "0", "id": "3c268027-f43c-0171-7425-1d799EXAMPLE", "detail-type": "AWS Health Event", "source": "aws.health", "account": "123456789012", "time": "2023-08-16T23:18:51Z", "region": "us-east-1", "resources": [ "cluster/service", "cluster/service" ], "detail": { "eventArn": "arn:aws:health:us-east-1::event/ECS/AWS_ECS_TASK_PATCHING_RETIREMENT/AWS_ECS_TASK_PATCHING_RETIREMENT_test1", "service": "ECS", "eventScopeCode": "ACCOUNT_SPECIFIC", "communicationId": "7988399e2e6fb0b905ddc88e0e2de1fd17e4c9fa60349577446d95a18EXAMPLE", "lastUpdatedTime": "Wed, 16 Aug 2023 23:18:52 GMT", "eventRegion": "us-east-1", "eventTypeCode": "AWS_ECS_TASK_PATCHING_RETIREMENT", "eventTypeCategory": "scheduledChange", "startTime": "Wed, 16 Aug 2023 23:18:51 GMT", "endTime": "Fri, 18 Aug 2023 23:18:51 GMT", "eventDescription": [ { "language": "en_US", "latestDescription": "\\nA software update has been deployed to Fargate which includes CVE patches or other critical patches. No action is required on your part. All new tasks launched automatically uses the latest software version. For existing tasks, your tasks need to be restarted in order for these updates to apply. Your tasks running as part of the following ECS Services will be automatically updated beginning Wed, 16 Aug 2023 23:18:51 GMT.\\n\\nAfter Wed, 16 Aug 2023 23:18:51 GMT, the ECS scheduler will gradually replace these tasks, respecting the deployment settings for your service. Typically, services should see little to no interruption during the update and no action is required. When AWS stops tasks, AWS uses the minimum healthy percent (1) and launches a new task in an attempt to maintain the desired count for the service. By default, the minimum healthy percent of a service is 100 percent, so a new task is started first before a task is stopped. Service tasks are routinely replaced in the same way when you scale the service or deploy configuration changes or deploy task definition revisions. If you would like to control the timing of this restart you can update the service before Wed, 16 Aug 2023 23:18:51 GMT, by running the update-service command from the ECS command-line interface specifying force-new-deployment for services using Rolling update deployment type. For example:\\n\\n$ aws ecs update-service -service service_name \\\n--cluster cluster_name -force-new-deployment\\n\\nFor services using Blue/Green deployment type with AWS CodeDeploy:\\nPlease refer to create-deployment document (2) and create new deployment using same task definition revision.\\n\\nFor further details on ECS deployment types, please refer to ECS Deployment Developer Guide (1).\\nFor further details on Fargate's update process, please refer to the AWS Fargate User Guide (3).\\nIf you have any questions or concerns, please contact AWS Support (4).\\n\\n(1) https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-types.html\\n(2) https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment.html\\n(3) https://docs.aws.amazon.com/AmazonECS/latest/userguide/task-maintenance.html\\n(4) https://aws.amazon.com/support\\n\\nA list of your affected resources(s) can be found in the 'Affected resources' tab in the 'Cluster/ Service' format in the AWS Health Dashboard. \\n\\n" } ], "affectedEntities": [ { "entityValue": "cluster/service" }, { "entityValue": "cluster/service" } ] } }
  • Email

    将向注册的电子邮件发送一封电子邮件以获取 AWS 账户 身份证。

我可以更改任务退休等待时间吗?

您可以对 Fargate 开始停用任务的时间进行配置。对于需要立即应用更新的工作负载,请选择即时设置(0)。当您需要更多控制时,例如,当任务只能在特定时间段内停止时,请配置 7 天(7)或 14 天(14)选项。

建议您选择较短的等待时间,以便更快获得较新的平台版本修订版。

通过运行、以 root 用户put-account-setting-defaultput-account-setting管理用户身份配置等待时间。将 fargateTaskRetirementWaitPeriod 选项用于设置为以下值之一的 namevalue 选项:

  • 0- AWS 发送通知,并立即开始停用受影响的任务。

  • 7- AWS 发送通知,等待 7 个日历日后才开始停用受影响的任务。

  • 14 - AWS 发送通知,等待 14 个日历日后才开始停用受影响的任务。

默认值为 7 天。

有关更多信息,请参阅《亚马逊弹性容器服务 API 参考put-account-setting中的put-account-setting-default和。

有关更多信息,请参阅 AWS Fargate 任务退休等待时间

我能否通过其他 AWS 服务收到任务停用通知?

AWS 向 AWS Health Dashboard 和上的主要电子邮件联系人发送任务停用通知 AWS 账户。 AWS Health Dashboard 提供了与其他 AWS 服务的许多集成,包括 EventBridge。您可以使用 EventBridge 自动显示通知(例如,将消息转发到 ChatOps 工具)。有关更多信息,请参阅解决方案概述:捕获任务停用通知

我可以在任务计划完成后更改任务停用吗?

不是。 该计划基于任务停用等待时间,默认值为 7 天。如果您需要更多时间,可以选择将等待时间配置为 14 天。有关更多信息,请参阅 我可以更改任务退休等待时间吗?。此配置的更改适用于将来安排的退休。目前计划的退休不受影响。如果您还有其他疑问,请联系 AWS Support。

我可以控制任务替换的时间吗?

对于使用滚动部署的服务,您可以在停update-service用开始时间之前使用force-deployment选项更新服务。

以下update-service示例使用该force-deployment选项。

aws ecs update-service —service service_name \ --cluster cluster_name \ --force-new-deployment

对于使用蓝/绿部署的服务,您需要在中创建新的部署。 AWS CodeDeploy有关如何创建部署的信息,请参阅参考中的创建-部署。AWS Command Line Interface

Amazon ECS 如何处理服务中的任务?

当 Fargate 停用期开始时,Amazon ECS 会逐渐取代服务中受影响的任务。当 Amazon ECS 停止某项任务时,它会使用该服务的最低健康百分比并启动一项新任务来维持该服务的所需任务数。由于默认的最低生命值百分比为 100,因此新任务是在任务停止之前启动的。在扩展服务、部署配置更改或部署任务定义修订时,通常会以相同的方式替换服务任务。有关最低健康百分比的更多信息,请参阅部署配置

Amazon ECS 能否自动处理独立任务?

不是。 AWS 无法为由RunTask计划任务(例如通过 EventBridge 调度程序)或 AWS Step Functions启动的独立任务创建替换任务。 AWS Batch Amazon ECS 仅管理属于服务一部分的任务。