Upload
wyn-b-van-devanter
View
199
Download
5
Embed Size (px)
Citation preview
Deploying a (Dockerized) application onto
EC2 Container Service (ECS)
Wyn Van Devanter
@wynv
EC2 Container Service (ECS)
• Manages clusters of EC2 instances for running containers
• Takes care of installing, operating and scaling a cluster management infrastructure
EC2 Container Service (ECS)
• Container management with API
• Centralized service to get cluster state
• Schedules the placement of containers across your cluster based on resources needs, isolation policies, and availability requirements
• Can integrate your own scheduler
• Integrated with other EC2 and AWS services and features
Key terms
• Cluster – logical grouping of EC2 instances, each with ECS container agent installed
• Container Instance - EC2 instance with container agent that runs containers in ECS
• Task Definition (like docker-compose.yml) – blueprint for the app to run in ECS; describes containers to run for app, and where environment variables can go
• Task – running instance of a task definition
• Service – keeps 1+ tasks running
• Elastic Container Registry (ECR)
ECS Clusters
• Run containers across instances in availability zones in a region
• Cluster contains EC2 instances (called container instances). ECS-optimized AMIs are available.
• Instances contain the ECS container agent • Sends information about the instance's current running tasks and resource
utilization to Amazon ECS
• Starts and stops tasks whenever it receives a request from Amazon ECS
Running apps on ECS
• Define task definitions to specify what container images to run across your clusters
• Container images are pulled from container registries (i.e. ECR)
• Services can be used with a task definition to keep a desired number of app instances running
Task definitions
• To prepare your application to run on Amazon ECS, you create a task definition.
• JSON file that describes one or more containers run to form your application; blueprint • Similar to the Docker Compose file and can be generated from one
• Specify various parameters for your application, such as: • which image(s) to use
• which ports should be opened
• what data volumes should be used
• where the container(s) should be placed
Tasks
• An instantiation of a task definition on a container instance within your cluster
• The Amazon ECS task scheduler is responsible for placing tasks on container instances
• Restarted as needed
Services
• You can define a service that runs and maintains a specified number of tasks simultaneously
• Manages running your application
• Allows scaling more instances (containers) of your app as needed
ECS setup
• Setting up IAM accounts for ECS management and deployment
• Setting up ECS for application deployment
• Setting up CI for automatic build and deployment
Setting up IAM accounts for ECS managementand deployment• IAM account for ECS management (i.e. creating cluster, load balancer)
• IAM account for ECS deployment (i.e. updating services and task definitions)
• Groups
Setting up ECS for application deployment
• Create cluster
• Create EC2 Container Registry (ECR) for app
• Set up load balancer for app
Setting up ECS for application deployment
• Create a task definition for the app first environment (i.e. dev/staging or production)
• Create a service to run the task definition
• Repeat for each environment, setting their environment variables
Setting up CI for automatic build and deployment
• Set environment variables for app in CI (i.e. cluster name, task definition base name, AWS account ID)
• Link to repository with app w/.travis.yml & deployment bash scripts
Deploying
• TravisCI detects check-in
• Builds app via Docker & pushes to ECR
• Deploys using task definition
App infrastructure
• API app in a container (ASP.NET Core)
• PostgreSQL container, data mounted via volume
• EC2 Container Service (ECS) 2-node cluster with ECR, load balancer, AWS Certificates and Route 53
• Travis with bash scripts for CI/CD
Thanks! @wynv
o Docs: Overview & Key Concepts http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html
o Docs: Core Setup Steps, http://docs.aws.amazon.com/AmazonECS/latest/developerguide/get-set-up-for-amazon-ecs.html
o Reference architecture for ECS w/deployment pipeline (CloudFormation), https://github.com/awslabs/ecs-refarch-continuous-deployment/blob/master/templates/deployment-pipeline.yaml
o ECS IAM Policies, http://docs.aws.amazon.com/AmazonECS/latest/developerguide/IAM_policies.html
o Sample app ready for ECS with task definition, https://github.com/excellalabs/ecs-deploy-setup