Amazon Outposts 上的 Amazon Elastic Container Service - Amazon Elastic Container Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon Outposts 上的 Amazon Elastic Container Service

Amazon Outposts 在本地设施中启用本机 Amazon 服务、基础设施和操作模型。在 Amazon Outposts 环境中,您可以使用与 Amazon Web Services 云 中相同的 Amazon API、工具和基础设施。

Amazon Outposts 上的 Amazon ECS 非常适合需要靠近本地数据和应用程序运行的低延迟工作负载。

有关 Amazon Outposts 的更多信息,请参阅《Amazon Outposts 用户指南》。https://docs.amazonaws.cn/outposts/latest/userguide/what-is-outposts.html

注意事项

以下是在 Amazon Outposts 上使用 Amazon ECS 的注意事项:

  • Amazon Elastic Container Registry、Amazon Identity and Access Management 和网络负载均衡器在 Amazon 区域而不是 Amazon Outposts 上运行。这将增加这些服务和容器之间的延迟。

  • Amazon Fargate 在 Amazon Outposts 上不可用。

以下是 Amazon Outposts 的网络连接注意事项:

  • 如果您的 Amazon Outposts 与其 Amazon 区域之间的网络连接丢失,您的集群将继续运行。但是,在恢复连接之前,您无法创建新集群或对现有集群执行新操作。如果实例出现故障,则不会自动替换该实例。CloudWatch Logs 代理将无法更新日志和事件数据。

  • 建议在 Amazon Outposts 与其 Amazon 区域之间提供可靠且高度可用的低延迟连接。

先决条件

以下是在 Amazon Outposts 上使用 Amazon ECS 的先决条件:

  • 您必须已在本地数据中心中安装并配置了 Outpost。

  • Outpost 与其 Amazon 区域之间必须具有可靠的网络连接。

在 Amazon Outposts 上创建集群

要使用 Amazon CLI 在 Amazon Outposts 上创建 Amazon ECS 集群,请指定与您的 Amazon Outposts 关联的安全组和子网 。

创建与您的 Amazon Outposts 关联的子网。

aws ec2 create-subnet \ --cidr-block 10.0.3.0/24 \ --vpc-id vpc-xxxxxxxx \ --outpost-arn arn:aws:outposts:us-west-2:123456789012:outpost/op-xxxxxxxxxxxxxxxx \ --availability-zone-id usw2-az1

以下示例在 Amazon Outposts 上创建一个 Amazon ECS 集群。

  1. 创建具有 Amazon Outposts 权限的角色和策略。

    role-policy.json 文件是包含资源效果和操作的策略文档。有关文件格式的信息,请参阅 IAM API 参考中的 PutRolePolicy

    aws iam create-role –-role-name ecsRole \ --assume-role-policy-document file://ecs-policy.json aws iam put-role-policy --role-name ecsRole --policy-name ecsRolePolicy \ --policy-document file://role-policy.json
  2. 在 Amazon Outposts 创建具有权限的 IAM 实例配置文件。

    aws iam create-instance-profile --instance-profile-name outpost aws iam add-role-to-instance-profile --instance-profile-name outpost \ --role-name ecsRole
  3. 创建 VPC。

    aws ec2 create-vpc --cidr-block 10.0.0.0/16
  4. 为容器实例创建安全组,为 Amazon Outposts 指定适合的 CIDR 范围。(此步骤不同于 Amazon Outposts。)

    aws ec2 create-security-group --group-name MyOutpostSG aws ec2 authorize-security-group-ingress --group-name MyOutpostSG --protocol tcp \ --port 22 --cidr 10.0.3.0/24 aws ec2 authorize-security-group-ingress --group-name MyOutpostSG --protocol tcp \ --port 80 --cidr 10.0.3.0/24
  5. 创建集群。

  6. 定义 Amazon ECS 容器代理环境变量以将实例启动到上一步创建的集群中,并定义您想添加的所有标签以帮助识别集群(例如,Outpost 表示集群用于 Outpost)。

    #! /bin/bash cat << ‘EOF’ >> /etc/ecs/ecs.config ECS_CLUSTER=MyCluster ECS_IMAGE_PULL_BEHAVIOR=prefer-cached ECS_CONTAINER_INSTANCE_TAGS={“environment”: ”Outpost”} EOF
    注意

    为了避免因从区域中的 Amazon ECR 拉取容器映像而导致的延迟,请使用映像缓存。为此,每次运行任务时,请将 Amazon ECS 代理配置为默认使用实例本身的缓存映像,方法是将 ECS_IMAGE_PULL_BEHAVIOR 设置为 prefer-cached

  7. 创建容器实例,指定该实例 Amazon Outposts 应运行的VPC和子网以及 Amazon Outposts 上可用的实例类型。(此步骤不同于 Amazon Outposts。)

    userdata.txt 文件包含用户数据,实例可使用这些数据执行常见的自动配置任务,甚至是在实例启动后运行脚本。有关 API 调用文件的信息,请参阅《Amazon EC2 用户指南》中的启动时在 Linux 实例上运行命令

    aws ec2 run-instances --count 1 --image-id ami-xxxxxxxx --instance-type c5.large \ --key-name aws-outpost-key –-subnet-id subnet-xxxxxxxxxxxxxxxxx \ --iam-instance-profile Name outpost --security-group-id sg-xxxxxx \ --associate-public-ip-address --user-data file://userdata.txt
    注意

    向集群添加其他实例时,也使用此命令。集群中部署的任何容器都将置于该特定 Amazon Outposts 上。

  8. 注册您的任务定义。使用以下命令并将 ecs-task.json 替换为您的任务定义名称。

    aws ecs register-task-definition --cli-input-json file://ecs-task.json
  9. 运行任务或创建服务。

    Run the task
    aws ecs run-task --cluster mycluster --count 1 --task-definition outpost-app:1
    Create the service
    aws ecs create-service –-cluster mycluster --service-name outpost-service \ --task-definition outpost-app:1 --desired-count 1