AWS Outposts 上的 Amazon Elastic Container Service - Amazon Elastic Container Service

AWS Outposts 上的 Amazon Elastic Container Service

AWS Outposts 會在內部部署設施中啟用原生 AWS 服務、基礎設施和操作模型。在 AWS Outposts 環境中,您可以使用您在 AWS 雲端中所使用的相同 AWS API、工具及基礎結構。

AWS Outposts 上的 Amazon ECS 適合需要靠近內部部署資料和應用程式執行的低延遲工作負載。

如需有關 AWS Outposts 的詳細資訊,請參閱《AWS Outposts 使用者指南》

考量事項

以下是在 AWS Outposts 上使用 Amazon ECS 的考量事項:

  • Amazon Elastic Container Registry、AWS Identity and Access Management 和 Network Load Balancer 在 AWS 區域執行,而不是在 AWS Outposts。這將提高這些服務和容器之間的延遲。

  • AWS Fargate 在 AWS Outposts 上無法使用。

以下是網路連線能力考量 AWS Outposts:

  • 如果 AWS Outposts 及其 AWS 區域之間的網路連線中斷,您的叢集仍將繼續運作。不過,在連線恢復之前,您將無法建立新叢集或對現有叢集採取新動作。在執行個體失敗的情況下,執行個體將不會被自動替換。CloudWatch Logs 代理程式將無法更新記錄檔和事件資料。

  • 建議您在 AWS Outposts 與其 AWS 區域之間提供可靠、高可用性和低延遲的連線能力。

先決條件

以下是在 AWS Outposts 上使用 Amazon ECS 的先決條件:

  • 內部部署資料中心必須已安裝和設定 Outpost。

  • Outpost 與其 AWS 區域之間必須有可靠的網路連線。

AWS Outposts 叢集建立概觀

下列是組態概觀:

  1. 在 AWS Outposts 上建立具有權限的角色和政策。

  2. 在 AWS Outposts 上建立具有權限的 IAM 執行執行個體設定檔。

  3. 建立 VPC,或使用與 AWS Outposts 位於同一區域的現有 VPC。

  4. 建立子網路,或使用與 AWS Outposts 相關聯的現有子網路。

    此即容器執行個體執行所在的子網路。

  5. 在叢集中建立容器執行個體的安全群組。

  6. 建立 Amazon ECS 叢集

  7. 定義 Amazon ECS 容器代理程式環境變數,將執行個體啟動至叢集中。

  8. 執行一個容器。

如需有關如何將 Amazon ECS 與 AWS Outposts 整合的詳細資訊,請參閱 Extend Amazon ECS across two AWS Outposts racks

以下範例會在 AWS Outposts 上建立 Amazon ECS 叢集。

  1. 在 AWS 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. 在 AWS 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. 建立與 AWS 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
  5. 為容器執行個體建立安全群組,指定 AWS Outposts 適當的 CIDR 範圍。(對 AWS 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
  6. 建立叢集。

  7. 定義 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 拉提取容器映像造成的延遲,請使用映像快取。若要進行此操作,請在每次執行工作時將 ECS_IMAGE_PULL_BEHAVIOR 設為 prefer-cached,以便將 Amazon ECS 代理程式設定為預設,在執行個體本身上使用快取的映像。

  8. 建立容器執行個體,指定 AWS Outposts 應執行此執行個體的 VPC 和子網路,以及 AWS Outposts 上可用的執行個體類型。(對 AWS Outposts 而言,此步驟是不同的。)

    userdata.txt 檔案中包含使用者資料,執行個體可以使用這些使用者資料來執行常見的自動化組態任務,甚至在執行個體啟動之後執行指令碼。如需有關 API 呼叫檔案的資訊,請參閱 Amazon EC2 User Guide 中的 Run commands on your Linux instance at launch

    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
    注意

    將其他執行個體新增至叢集時,也會使用此指令。在叢集中部署的任何容器都會放置在該特定 AWS Outposts 上。