6

我正在使用 Fargate 启动 ECS 任务,并且容器在 PENDING 几分钟后最终处于 STOPPED 状态。状态给出以下错误消息:

CannotPullContainerError: context canceled

我正在使用 PrivateLink 允许 ECS 主机与 ECR 注册表对话,而无需通过公共 Internet,这就是它的配置方式(无服务器语法增强 CloudFormation):

      Properties:
        PrivateDnsEnabled: true
        ServiceName: com.amazonaws.ap-southeast-2.ecr.dkr
        SubnetIds:
          - { Ref: frontendSubnet1 }
          - { Ref: frontendSubnet2 }
        VpcEndpointType: Interface
        VpcId: { Ref: frontendVpc }

关于导致错误的任何想法?

4

2 回答 2

4

您是否还添加了 S3 端点?这是我的模板的一个工作片段,我能够通过 aws 支持解决这个问题:

  EcrDkrEndpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
  PrivateDnsEnabled: true
  SecurityGroupIds: [!Ref 'FargateContainerSecurityGroup']
  ServiceName: !Sub 'com.amazonaws.${AWS::Region}.ecr.dkr'
  SubnetIds: [!Ref 'PrivateSubnetOne', !Ref 'PrivateSubnetTwo']
  VpcEndpointType: Interface
  VpcId: !Ref 'VPC'

对于 S3,您需要知道路由表是必要的 - 通常您希望使用与 Internet 网关相同的路由表,其中包含路由 0.0.0.0/0

  S3Endpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
  ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
  VpcEndpointType: Gateway
  VpcId: !Ref 'VPC'
  RouteTableIds: [!Ref 'PrivateRouteTable'] 

如果没有 cloudwatch 的端点,您将再次失败,这也是必要的:

  CloudWatchEndpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
  PrivateDnsEnabled: true
  SecurityGroupIds: [!Ref 'FargateContainerSecurityGroup']
  ServiceName: !Sub 'com.amazonaws.${AWS::Region}.logs'
  SubnetIds: [!Ref 'PrivateSubnetOne', !Ref 'PrivateSubnetTwo']
  VpcEndpointType: Interface
  VpcId: !Ref 'VPC'

编辑:私有路由表:

  PrivateRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachement
Properties:
  RouteTableId: !Ref 'PublicRouteTable'
  DestinationCidrBlock: '0.0.0.0/0'
  GatewayId: !Ref 'InternetGateway'
于 2019-11-13T15:37:41.150 回答
1

我发现我不仅需要 s3 的 vpc 端点、aws 日志和两个 ecr 端点,如@graphik_ 的答案中所述,而且我还需要确保端点上的安全组允许从安全组上的安全组对 HTTPS 进行入口访问远景容器。

Farscape 容器上的安全组需要通过 HTTPS 对 vpce 端点安全组以及 pl-7ba54012 IP 组(即 s3)进行出口访问。

这和路由表中到 pl-7ba54012 的路由似乎是全貌。

vpce 上也有策略,我将其保留为默认的“所有访问权限”,但您可以将其强化为仅允许从运行 Fargate 容器的角色进行访问。

于 2020-07-17T11:40:01.587 回答