我之前在 Fargate 上啟動了我的 ECS 任務,它運行良好。任務定義有Network mode = awsvpc,集群沒有與任何容量提供者相關聯。
現在我正在嘗試使用EC2“啟動型別”(網路模式仍然是awsvpc,目標組型別是IP),
我使用
ami-0da25582fb45be38c(amzn2-ami-ecs-hvm-2.0.20220822-x86_64-ebs) 和特定的 vpcID / 安全組 / 子網創建了具有啟動配置的自動縮放組我在我的 ECS 集群中創建了容量提供程式,并將其與我在步驟 1 中創建的自動縮放組相關聯
我重新創建了 ECS 服務并指定了我在步驟 2 中創建的容量提供程式,作為“自定義容量提供程式策略”,
weight=100, base=1并且還指定了我在步驟 1 中使用的 vpcID/安全組/子網現在我設定
min=0, desired=1, max=1在自動縮放組中。我看到一個 EC2 實體成功啟動并運行。我可以使用 PEM 證書通過 SSH 連接到它,當我運行時docker ps -a,我可以看到amazon/amazon-ecs-agent:latest容器不斷啟動,立即退出,15 秒后再次啟動,退出等等。不確定這是否是預期的最后,現在我設定
min=0, desired=1, max=1了我的 ECS 服務。我可以在任務串列中看到一項任務,但它的狀態被卡住PROVISIONING并且沒有改變。相應地,沒有分配給它的 EC2 實體
似乎 ecs-agent 不斷重啟,這就是 ECS 服務無法使用 EC2 實體執行任務的原因。任何人都知道為什么 ecs-agent 會重新啟動?
UPD。檢查了 ecs-agent 的 docker 日志:
$ docker logs -f ecs-agent
level=info time=2022-09-06T05:20:25Z msg="Successfully got ECS instance credentials from provider: EC2RoleProvider" module=instancecreds_linux.go
level=info time=2022-09-06T05:20:25Z msg="Starting Amazon ECS Agent" commit="a1a5ecbc" version="1.62.2"
level=info time=2022-09-06T05:20:25Z msg="Loading configuration"
level=warn time=2022-09-06T05:20:25Z msg="Unable to fetch user data: EC2MetadataError: failed to make EC2Metadata request\n\tstatus code: 404, request id: \ncaused by: <?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\t\t \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n <head>\n <title>404 - Not Found</title>\n </head>\n <body>\n <h1>404 - Not Found</h1>\n </body>\n</html>\n" module=config.go
level=info time=2022-09-06T05:20:25Z msg="Successfully got ECS instance credentials from provider: EC2RoleProvider" module=instancecreds_linux.go
level=info time=2022-09-06T05:20:25Z msg="Successfully got ECS instance credentials from provider: EC2RoleProvider" module=instancecreds_linux.go
level=info time=2022-09-06T05:20:25Z msg="Image excluded from cleanup" image="amazon/amazon-ecs-pause:0.1.0"
level=info time=2022-09-06T05:20:25Z msg="Image excluded from cleanup" image="amazon/amazon-ecs-pause:0.1.0"
level=info time=2022-09-06T05:20:25Z msg="Image excluded from cleanup" image="amazon/amazon-ecs-agent:latest"
level=info time=2022-09-06T05:20:25Z msg="Event stream ContainerChange start listening..." module=eventstream.go
level=info time=2022-09-06T05:20:25Z msg="Loading state!" module=state_manager.go
level=info time=2022-09-06T05:20:25Z msg="eni watcher has been initialized" module=watcher_linux.go
level=info time=2022-09-06T05:20:25Z msg="Registering Instance with ECS"
level=info time=2022-09-06T05:20:25Z msg="Remaining mem: 956" module=client.go
level=error time=2022-09-06T05:20:25Z msg="Unable to register as a container instance with ECS: ClientException: The referenced cluster was inactive." module=client.go
level=info time=2022-09-06T05:20:25Z msg="Remaining mem: 956" module=client.go
level=error time=2022-09-06T05:20:25Z msg="Unable to register as a container instance with ECS: ClientException: The referenced cluster was inactive." module=client.go
level=error time=2022-09-06T05:20:25Z msg="Error registering container instance" error="ClientException: The referenced cluster was inactive."
我用于自動縮放組的角色具有以下 ECS 策略:
"ecs:CreateCluster",
"ecs:ListClusters",
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:UpdateContainerInstancesState",
"ecs:Submit*",
也許問題出在 AMI 中,我可以使用另一個?雖然ecs-init版本1.62.2如此,但它是最新的
uj5u.com熱心網友回復:
似乎代理嘗試附加到的 ECS 集群不存在。檢查ECS_CLUSTER檔案內部的值/etc/ecs/ecs.config。如果未設定,則會獲取一個值,并且很可能您的 ECS 中default沒有指定的集群。default
編輯:您可以在 AMI 中將其設定為適當的值并使用新的 AMI 在集群中啟動新實體,或者您可以user data在啟動模板中更新以在新實體出現時設定值。
有關 ECS 容器代理配置的更多資訊:https ://github.com/aws/amazon-ecs-agent/blob/master/README.md
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/505084.html
標籤:亚马逊网络服务 码头工人 亚马逊-ec2 亚马逊-ecs 亚马逊
上一篇:帶有docker-compose應用程式的GoogleJib,在將映像重建到Docker守護程式后重新啟動應用程式的快速方法
