【问题标题】:Attach Volume EFS in ECS在 ECS 中附加卷 EFS
【发布时间】:2020-11-20 16:02:10
【问题描述】:

在尝试将 EFS 文件系统与 ECS 一起挂载时,我收到以下错误:

ResourceInitializationError: 无法调用 EFS utils 命令来设置 EFS 卷:stderr: mount.nfs4: Connection reset by peer : EFS utils 命令执行不成功;代码:32

我的堆栈:

--- 
  AWSTemplateFormatVersion: "2010-09-09"
  Description: "Template Test"
  Outputs: 
    FileSystemID: 
      Description: "File system ID"
      Value: 
        Ref: FileSystem
  Parameters: 
    VolumeName: 
      Default: myEFSvolume
      Description: "The name to be used for the EFS volume"
      MinLength: "1"
      Type: String
  Resources: 
    ECSCluster: 
      Properties: 
        ClusterName: jenkins-cluster
      Type: "AWS::ECS::Cluster"
    EFSMountTarget1: 
      Properties: 
        FileSystemId: 
          Ref: FileSystem
        SecurityGroups: 
          - "sg-0082cea75ba714505"
        SubnetId: "subnet-0f0b0d3aaada62b6c"
      Type: "AWS::EFS::MountTarget"
    FileSystem: 
      Properties: 
        Encrypted: true
        FileSystemTags: 
          - Key: Name
            Value: 
              Ref: VolumeName
        PerformanceMode: generalPurpose
      Type: "AWS::EFS::FileSystem"
    JenkinsService: 
      Type: "AWS::ECS::Service"
      Properties: 
        Cluster: 
          Ref: ECSCluster
        DesiredCount: 2
        LaunchType: FARGATE
        NetworkConfiguration: 
          AwsvpcConfiguration:
            AssignPublicIp: ENABLED
            SecurityGroups: 
              - "sg-0082cea75ba714505"
            Subnets: 
              - "subnet-0f0b0d3aaada62b6c"
        PlatformVersion: "1.4.0"
        ServiceName: JenkinsService
        
        TaskDefinition: 
          Ref: JenkinsTaskDef
    JenkinsTaskDef: 
      Type: "AWS::ECS::TaskDefinition"
      Properties:
        Cpu: 2048
        Memory: 4096
        Family: efs-example-task-fargate
        NetworkMode: awsvpc
        TaskRoleArn: "arn:xxxxx/ecs"
        ExecutionRoleArn: "arn:xxxxxx:role/ecs"
        RequiresCompatibilities:
          - FARGATE 
        ContainerDefinitions: 
          - Cpu: 1024
            Memory: 2048
            PortMappings:
              - HostPort: 8080
                ContainerPort: 8080
              - HostPort: 50000
                ContainerPort: 50000
            image: "xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/sample:latest"
            mountPoints: 
              - containerPath: /var/jenkins_home
                readOnly: false
                sourceVolume: myEfsVolume
            name: jenkins
        volumes:
          - name: myEfsVolume  
            efsVolumeConfiguration: 
              fileSystemId: 
                Ref: FileSystem
              rootDirectory: /var/jenkins_home
              transitEncryption: ENABLED 
    

我正在按照文档执行:

https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_EFSVolumeConfiguration.html

【问题讨论】:

    标签: amazon-web-services docker jenkins amazon-ecs amazon-efs


    【解决方案1】:

    您需要在网络接口和任务定义上的安全组上打开入站端口 2049。即使您将其设置为为您创建安全组,它也不会自动设置。

    【讨论】:

    • 您可能会注意到要确保您的子网能够连接到您的 EFS 卷。
    • 对我来说,它仅在我从 EFS 文件系统中删除所有策略时才有效。请记住,我所做的只是用于测试目的的临时解决方案。
    【解决方案2】:

    现在已经有一段时间了,但我遇到了同样的问题,理解如何进行有点令人困惑。创建 EFS 卷时,您需要为每个子网选择一个 VPC 和一个安全组。

    您需要编辑此安全组以添加type NFS 的入站规则以允许访问(tcp 端口 2049)到您要允许访问的 ECS 集群服务的安全组标识符。为此,只需在 source 字段中选择自定义,然后在文本框中输入服务的安全组标识符。

    更多信息this article很好地描述了整个过程。

    【讨论】:

      【解决方案3】:

      如果您在将任务定义与卷关联时启用了 IAM 授权,您还需要更新其任务执行角色。您需要将访问 EFS 所需的策略附加到它。

      【讨论】:

        【解决方案4】:

        这些是在 AWS FARGATE 中挂载 EFS 需要做的事情:

        1. 将 2049 端口从应用层添加到 EFS sg 组(本例中为容器 sg)
        2. 使用策略更新 ECS FARGATE 任务执行角色以装载和写入 EFS
        3. EFS 子网的 NACL 在端口 2049 上有一个出站

        【讨论】:

          猜你喜欢
          • 2021-02-02
          • 2021-08-04
          • 2018-01-16
          • 2021-11-05
          • 2021-09-17
          • 2021-05-12
          • 2019-01-04
          • 2021-06-27
          相关资源
          最近更新 更多