本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
AWS PCS 的節點生命週期動作範例
下列範例使用 AWS CLI 來設定節點生命週期動作。您可以在使用 建立運算節點群組時定義生命週期動作create-compute-node-group,或使用 在現有的運算節點群組上新增或變更它們update-compute-node-group。兩個命令--node-lifecycle-actions的值相同。
跨階段的多個指令碼
此範例結合跨兩個生命週期階段的指令碼與不同的執行政策和錯誤行為。
aws pcs create-compute-node-group --regionregion\ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --subnet-idssubnet-ExampleID1\ --custom-launch-template id=lt-ExampleID1,version='1' \ --iam-instance-profile-arn=arn:InstanceProfile\ --scaling-config minInstanceCount=0,maxInstanceCount=10\ --instance-configs instanceType=t3.large\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Mount FSx Lustre", "scriptSource": { "scriptLocation": "s3://my-bucket/mount-fsx.sh" }, "arguments": ["fs-0abc123", "/scratch"], "executionPolicy": "EVERY_BOOT" }, { "name": "Join Active Directory", "scriptSource": { "scriptLocation": "s3://my-bucket/configure-ad.sh" }, "arguments": ["ad.example.com", "EXAMPLE"], "executionPolicy": "FIRST_BOOT_ONLY" } ], "nodeReady": [ { "name": "Configure CloudWatch logging", "scriptSource": { "scriptLocation": "s3://my-bucket/setup-cloudwatch.sh" }, "arguments": ["/aws/pcs/my-cluster"], "onError": "CONTINUE" } ] } }'
混合錯誤行為
此範例在相同階段使用關鍵和選用的指令碼。第一個 會在失敗時終止節點;第二個則繼續。
aws pcs create-compute-node-group --regionregion\ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --subnet-idssubnet-ExampleID1\ --custom-launch-template id=lt-ExampleID1,version='1' \ --iam-instance-profile-arn=arn:InstanceProfile\ --scaling-config minInstanceCount=0,maxInstanceCount=10\ --instance-configs instanceType=t3.large\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Install required packages", "scriptSource": { "scriptLocation": "s3://my-bucket/install-packages.sh" }, "onError": "TERMINATE" }, { "name": "Install optional tools", "scriptSource": { "scriptLocation": "s3://my-bucket/install-optional.sh" }, "onError": "CONTINUE" } ] } }'
使用檢查總和進行完整性驗證
新增 SHA-256 檢查總和,以便代理程式在其內容不相符時拒絕指令碼。
aws pcs update-compute-node-group \ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Mount EFS", "scriptSource": { "scriptLocation": "s3://my-bucket/mount-efs.sh", "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }, "arguments": ["fs-12345678", "/shared"] } ] } }'
重新啟動時啟用指令碼重新整理
scriptCachingPolicy 設定為 REFRESH_ON_REBOOT。此UpdateComputeNodeGroup呼叫是組態變更,因此會耗盡並取代現有的執行個體。取代完成後,執行個體會在每次重新開機時重新下載指令碼。然後,您可以更新 Amazon S3 中的指令碼內容,並在執行個體下次重新開機時收取變更,而無需進一步 API 呼叫。
aws pcs update-compute-node-group \ --cluster-identifiermy-cluster\ --compute-node-group-identifiermy-cng\ --node-lifecycle-actions '{ "stages": { "nodeBootstrapped": [ { "name": "Mount EFS", "scriptSource": { "scriptLocation": "s3://my-bucket/mount-efs.sh" }, "arguments": ["fs-12345678", "/shared"], "executionPolicy": "EVERY_BOOT" } ] }, "scriptCachingPolicy": "REFRESH_ON_REBOOT" }'
從 AWS ParallelCluster 引導操作遷移
許多現有的 AWS ParallelCluster 引導指令碼可正常搭配 AWS PCS 生命週期動作使用。 AWS PCS 提供依指令碼錯誤處理 (TERMINATE、 STOP_SEQUENCE或 CONTINUE) 和重新啟動控制 (FIRST_BOOT_ONLY 或 EVERY_BOOT)。 AWS PCS 預設為 FIRST_BOOT_ONLY。若要符合 ParallelCluster 行為 (在每次開機時執行),請將 executionPolicy設定為 EVERY_BOOT。
AWS ParallelCluster |
AWS PCS |
|---|---|
|
|
|
|
|
沒有 AWS PCS 對等項目 |