如何管理 Amazon ECS 任務的 EBS 磁碟區?

1 分的閱讀內容
0

我想在 Amazon Elastic Container Service (Amazon ECS) 任務中使用 Amazon Elastic Block Storage (Amazon EBS) 磁碟區。

解決方法

**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本

先決條件:

若要將新的 EBS 磁碟區附加到任務,請在 mountPoints 下的任務定義中指定以下組態

  • sourceVolume,請輸入要掛載磁碟區的名稱。
  • containerPath,請輸入容器執行個體中掛載磁碟區的路徑。
  • readOnly,請根據容器是否具有對磁碟區的唯讀存取權輸入TrueFalse

然後,將 configuredAtLaunch 設定為 True

任務定義範例:

{
    "family": "mytaskdef",
    "containerDefinitions": [
        {
            ....
            #Some fields removed from example
            ....
            "mountPoints": [
                {
                    "sourceVolume": "myEBSVolume",  
                    "containerPath": "/mount/ebs",  
                    "readOnly": true                
                }
            ]
        }
     ],
     ....
     #Some fields removed from example
     ....
     "volumes": [
        {
            "name": "myEBSVolume",                 
            "configuredAtLaunch": true
        }
    ]
}

將任務定義範本儲存為 JSON 檔案,然後執行 register-task-definition 來註冊任務定義:

aws ecs register-task-definition \
    --cli-input-json file://json_file_name.json \
    --region Region_name

**注意:**將 json_file_name.json 替換為您的 JSON 檔案,將 Region_name 替換為您的 AWS 區域。

然後,在執行獨立任務時,在部署時設定 Amazon EBS 磁碟區。或者,在建立或更新服務時進行設定。

若要使用現有 EBS 磁碟區中的資料,請建立該磁碟區的快照。然後,在任務定義中 VolumeConfigurations 下的 SnapshotID 中新增快照 ID。如需組態範例,請參閱在建立服務時設定磁碟區

相關資訊

對 Amazon EBS 磁碟區附加到 Amazon ECS 任務的問題進行疑難排解

將 Amazon EBS 磁碟區與 Amazon ECS 搭配使用

AWS 官方
AWS 官方已更新 2 個月前