Amazon 彈性容器服務 AWS Outposts - Amazon Elastic Container Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Amazon 彈性容器服務 AWS Outposts

AWS Outposts 在內部部署設施中啟用原生 AWS 服務、基礎架構和作業模型。在 AWS Outposts 環境中 AWS ,您可以使用與 AWS 雲端.

Amazon ECS on 非 AWS Outposts 常適合需要在鄰近現場部署資料和應用程式執行的低延遲工作負載。

若要取得有關的更多資訊 AWS Outposts,請參閱AWS Outposts 使用者指南

考量事項

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

  • Amazon 彈性容器登錄檔和 Network Load Balancer 在該 AWS 區域中執行,而不是在上執行 AWS Outposts。 AWS Identity and Access Management這將提高這些服務和容器之間的延遲。

  • AWS Fargate 不適用於 AWS Outposts。

以下是用於的網路連線考量 AWS Outposts:

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

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

必要條件

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

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

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

在上建立叢集 AWS Outposts

若要在上建立 Amazon ECS 叢集 AWS CLI,請指定要 AWS Outposts 與您 AWS Outposts的產生關聯的安全群組和子網路。

若要建立與您關聯的子網路 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

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

  7. 建立容器執行個體,指定 AWS Outposts 應執行此執行個體的 VPC 和子網路,以及 AWS Outposts上可用的執行個體類型。(此步驟是不同的 AWS 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
    注意

    將其他執行個體新增至叢集時,也會使用此指令。在叢集中部署的任何容器都會放置在該特定 AWS 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