AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
如何增加 AWS Fargate 上 Amazon ECS 容器的磁碟空間?
我想增加 AWS Fargate 上 Amazon Elastic Container Service (Amazon ECS) 容器的磁碟空間。
簡短描述
預設情況下,使用平台版本 1.40 啟動的 Fargate 任務包含一個大小為 20 GiB 的任務儲存空間,作為單一暫時性磁碟區。如果您需要超過 20 GiB 的儲存空間,請使用以下其中一種選項來設定更多儲存空間:
- 使用 Fargate 的暫時性儲存空間選項,可提供最多達 200 GiB 的儲存空間。暫時性儲存空間不是永續性儲存空間。
- 使用 Amazon Elastic File System (Amazon EFS) 磁碟區 實作可擴充的檔案儲存空間。Amazon EFS 磁碟區提供永續性儲存空間。
- 將 EBS 磁碟區附加到 Fargate,以用於儲存和資料密集型儲存需求。EBS 磁碟區選項不是永續性的。
**重要:**建立 Amazon EFS 磁碟區時,請使用指派給 Fargate 服務的相同 Amazon Virtual Private Cloud (Amazon VPC) 和子網路。
解決方法
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤,請參閱AWS CLI 錯誤疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
若要為 Fargate 上的 Amazon ECS 容器增加磁碟空間,請根據您的使用案例完成相關任務。
設定暫時性儲存空間
請完成下列步驟:
-
"containerDefinitions": [ { "memory": 128, "essential": true, "name": "nginx", "image": "nginx" } ] "ephemeralStorage": { "sizeInGiB": 30 } -
使用更新後的任務定義來執行任務。
**注意:**對於與服務關聯的任務,選取新的任務定義修訂來更新服務。
如需詳細資訊,請參閱將繫結掛接與 Amazon ECS 結合使用。
使用 Amazon EFS 磁碟區設定儲存空間
請完成下列步驟:
- 為您的 Amazon EFS 掛接目標建立一個安全群組。然後,新增傳入規則以接受來自來源任務安全群組,連接埠 2049 上的 NFS 流量。
- 建立 Amazon EFS 檔案系統,然後將安全群組附加到您的掛接目標。
**注意:**預設情況下,系統會在指定 AWS 區域的每個可用區域中設定一個掛接目標。選取 Fargate 服務的 VPC 子網路所在的所有可用區域。 - 記下您檔案系統的檔案系統 ID。例如:fs-12345678
- 建立或更新任務定義,以便為具有 Amazon EFS 檔案系統的 Amazon ECS 任務設定磁碟區。例如:
**注意:**將 fs-12345678 替換為您的檔案系統 ID。"volumes": [ { "name": "efs-test-volume", "efsVolumeConfiguration": { "fileSystemId": "fs-12345678", "transitEncryption": "ENABLED" } } ] - 使用容器定義區段,在您的容器內建立該磁碟區的掛接點。例如:
**注意:**containerPath 是容器內安裝磁碟區的路徑。sourceVolume 是您磁碟區的名稱。"containerDefinitions": [ { "memory": 128, "portMappings": [ { "hostPort": 80, "containerPort": 80, "protocol": "tcp" } ], "essential": true, "mountPoints": [ { "containerPath": "/mount/path/inside/container", "sourceVolume": "efs-test-volume" } ], "name": "nginx", "image": "nginx" } ] - 使用更新後的任務定義來執行該任務。
**注意:**對於與服務關聯的任務,選取新的任務定義修訂來更新服務。
將 EBS 磁碟區附加到 Fargate
請完成下列步驟:
-
建立或更新任務定義,以設定在啟動時要設定的 EBS 磁碟區。使用設定為 true 的 "configuredAtLaunch" 選項。例如:
"containerDefinitions": [ { "name": "nginx", "image": "public.ecr.aws/nginx/nginx:latest", "networkMode": "awsvpc", "portMappings": [ { "name": "nginx-80-tcp", "containerPort": 80, "hostPort": 80, "protocol": "tcp", "appProtocol": "http" } ], "mountPoints": [ { "sourceVolume": "myEBSVolume", "containerPath": "/mount/ebs", "readOnly": true } ] } ], "volumes": [ { "name": "myEBSVolume", "configuredAtLaunch": true } ] -
啟動獨立任務。或者,將任務作為服務的一部分啟動,並將磁碟區組態作為 JSON 的一部分。
獨立任務 JSON 範例:{ "cluster": "mycluster", "taskDefinition": "mytaskdef", "volumeConfigurations": [ { "name": "datadir", "managedEBSVolume": { "volumeType": "gp3", "sizeInGiB": 100, "roleArn": "arn:aws:iam:1111222333:role/ecsInfrastructureRole", "encrypted": true, "kmsKeyId": "arn:aws:kms:region:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" } } ] }**注意:**如上例所示,啟動任務不需要快照。
服務 JSON 範例:{ "cluster": "mycluster", "taskDefinition": "mytaskdef", "serviceName": "mysvc", "desiredCount": 2, "volumeConfigurations": [ { "name": "myEbsVolume", "managedEBSVolume": { "roleArn":"arn:aws:iam:1111222333:role/ecsInfrastructureRole", "snapshotId": "snap-12345" } } ] }**注意:**將 roleArn 替換為您的帳戶 ecsInfrastructureRole。將 snapshotId 替換為您要從中建立磁碟區的快照 ID。
- 語言
- 中文 (繁體)

相關內容
已提問 4 年前