Amazon Fargate 任务维护常见问题解答 - Amazon Elastic Container Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

什么是 Fargate 任务维护和停用?

Amazon 负责维护 Amazon Fargate 的底层基础设施。Amazon 确定何时需要将平台版本修订版替换为新修订版。这称为任务停用。当平台版本版本修订停用时,Amazon 会发送任务停用通知。我们会定期更新支持的平台版本以引入新版本,其中包含对 Fargate 运行时软件,以及底层依赖项(例如操作系统和容器运行时)的更新。提供较新修订版后,我们会停用旧版本,以确保所有客户工作负载均在最新修订版的 Fargate 平台版本上运行。当停用修订版时,系统会停用在该修订版上运行的所有任务。

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

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

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

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

当有新的平台版本修订版并需要替换为新修订版时,任务维护适用。如果底层 Fargate 主机出现问题,则 Amazon ECS 会更换主机而不发出任务停用通知。

任务停用通知中包含哪些内容?

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

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

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

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

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

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

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

  • 这些区域有:Amazon Health Dashboard

    您可以通过 Amazon EventBridge 将 Amazon Health 通知发送到存档存储器(例如 Amazon Simple Storage Service)、执行自动操作(例如运行 Amazon Lambda 函数)或其他通知系统(例如 Amazon Simple Notification Service)。有关更多信息,请参阅使用 Amazon EventBridge 监控 Amazon Health 事件。有关向 Amazon Chime、Slack 或 Microsoft Teams 发送通知的示例配置,请参阅 GitHub 上的 Amazon Health Aware 存储库。

    以下是一个示例 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

    将向注册的电子邮件发送一封电子邮件以获取 Amazon Web Services 账户 ID。

我可以更改任务停用等待时间吗?

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

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

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

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

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

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

默认值为 7 天。

有关更多信息,请参阅《Amazon Elastic Container Service API 参考》中的 put-account-setting-defaultput-account-setting

有关更多信息,请参阅 Amazon Fargate 任务停用等待时间

我可以通过其他 Amazon 服务获取任务停用通知吗?

Amazon 向 Amazon Health Dashboard 和 Amazon Web Services 账户 上的主要电子邮件联系人发送任务停用通知。Amazon Health Dashboard 提供了与其他 Amazon 服务(包括 EventBridge)的许多集成。您可以使用 EventBridge 自动显示通知(例如,将消息转发到 ChatOps 工具)。有关更多信息,请参阅 Solution overview: Capturing task retirement notifications

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

不可以。该计划基于任务停用等待时间,默认值为 7 天。如果您需要更多时间,则可以选择将等待期配置为 14 天。有关更多信息,请参阅 我可以更改任务停用等待时间吗?。此配置的更改适用于将来计划的停用。目前已计划的停用不受影响。如有任何疑问,请联系 Amazon Web Services Support。

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

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

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

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

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

Amazon ECS 如何处理属于服务一部分的任务?

当 Fargate 停用期开始时,Amazon ECS 会逐渐替换服务中受影响的任务。当 Amazon ECS 停止某项任务时,其使用服务的最小正常百分比并启动一个新任务,以保持服务所需的任务数。由于默认的最小正常百分比为 100,因此新任务会在任务停止之前启动。在扩缩服务、部署配置更改或部署任务定义修订版时,通常以相同的方式替换服务任务。有关最小正常百分比的更多信息,请参阅 部署配置

Amazon ECS 可以自动处理独立任务吗?

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