简体   繁体   English

使用 ECS-CLI 将多容器 Docker 应用程序部署到 AWS ECS Fargate

[英]Deploying multi-container docker application to AWS ECS Fargate using ECS-CLI

I need to deploy this project on AWS ECS (Preferably Fargate or EC2 worst case).我需要在 AWS ECS 上部署这个项目(最好是 Fargate 或 EC2 最坏的情况)。 Looking at the documentation I tried to deploy with single container and it works but with multi containers, due to the restrictions of ecs-cli I cannot use the docker-compose.yml straight from project hence I upload the docker images to ECR and then create a new docker-compose with the digests for respective conatiners.查看我尝试使用单个容器部署的文档,但它适用于多个容器,由于 ecs-cli 的限制,我无法直接从项目中使用 docker-compose.yml,因此我将 docker 图像上传到 ECR,然后创建一个新的 docker-compose 与相应容器的摘要。

Here is a link to the original docker-compose.yml .这是原始docker-compose.yml的链接。 Here is what my docker-compose looks like now after uploading images to ECR:这是我的 docker-compose 在将图像上传到 ECR 后的样子:

version: "3.0"
services:
    postgres:
        image: postgres:12  
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker

    db:
        image: sha256:123123123123123213213213213
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker   

    traefik:
        image: sha256:123123123123123213213213213
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker

    queue:
        image: sha256:123123123123123213213213213
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker
    
    flower:
        image: sha256:123123123123123213213213213
        env_file: 
            - .env
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker

    backend:
        image: sha256:123123123123123213213213213
        env_file: 
            - .env
        environment:
            - SERVER_NAME=${DOMAIN?Variable not set}
            - SERVER_HOST=https://${DOMAIN?Variable not set}
            - SMTP_HOST=${SMTP_HOST}
        ports:
            - "80:80"
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker

    celeryworker:
        image: sha256:123123123123123213213213213
        env_file:
            - .env
        environment:
            - SERVER_NAME=${DOMAIN?Variable not set}
            - SERVER_HOST=https://${DOMAIN?Variable not set}
            # Allow explicit env var override for tests
            - SMTP_HOST=${SMTP_HOST?Variable not set}
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker
    

    frontend:
        image: sha256:123123123123123213213213213
        logging:
            driver: awslogs
            options: 
                awslogs-group: aws-ecs-docker-test
                awslogs-region: ap-south-1
                awslogs-stream-prefix: docker
    
volumes:
  app-db-data:

Here is the ecs-params.yml:这是 ecs-params.yml:

version: 1
task_definition:
  task_execution_role: ecsTaskExecutionRole
  ecs_network_mode: awsvpc
  task_size:
    mem_limit: 0.5GB
    cpu_limit: 256
run_params:
  network_configuration:
    awsvpc_configuration:
      subnets:
        - subnet-123123123
        - subnet-123123123
      security_groups:
        - sg-123123123
      assign_public_ip: ENABLED

The ecsTaskExecutionRole has all access to ECS, ECR & Cloudwatch logs. ecsTaskExecutionRole 拥有对 ECS、ECR 和 Cloudwatch 日志的所有访问权限。 However whenever I deploy, ecs creates a few task definitions and then times out:但是,每当我部署时,ecs 都会创建一些任务定义,然后超时:

Deployment has not completed: Running count has not changed for 5.00 minutes

Even if I extend the timeout to 30 mins it doesn't change the output.即使我将超时延长到 30 分钟,它也不会改变输出。 The logs output nothing so I am quite clueless as to what could be the potential issue.日志没有输出任何内容,因此我对可能存在的潜在问题一无所知。 I am new to Devops & Docker so I'm not sure what I am actually missing.我是 Devops 和 Docker 的新手,所以我不确定我实际上缺少什么。

I was able to fix this issue eventually.我最终能够解决这个问题。 The issue was with the traefik image and the lack of Cloudwatch permissions given to the IAM role.问题在于 traefik 图像以及缺乏授予 IAM 角色的 Cloudwatch 权限。

Alternatively to ecs-cli, I would suggest ECS Compose-X which will allow you to plug&play to your existing network (VPC) and takes care of all the rest (IAM, Security Groups etc).作为 ecs-cli 的替代方案,我建议使用ECS Compose-X ,它允许您即插即用到现有网络 (VPC) 并处理所有其他问题(IAM、安全组等)。 Additionally if you wanted to link your services to other AWS resources, you can use it to discover these resources (if already exist) or create new ones, and again, everything with regards to IAM and Security will be taken care of for you.此外,如果您想将您的服务链接到其他 AWS 资源,您可以使用它来发现这些资源(如果已经存在)或创建新资源,同样,与 IAM 和安全性有关的一切都将为您处理。

If you created, say, a kinesis stream, your container also would be given the ARN and name of the stream via env var automatically so you never need to name your resources, you'd always have a pointer to it.如果您创建了一个 kinesis 流,那么您的容器也将通过 env var 自动获得流的 ARN 和名称,因此您永远不需要命名您的资源,您总是有一个指向它的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM