Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Deliver Docker Containers Continuously on AWS

554 views

Published on

Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/2qtLIKb.

Philipp Garbe discusses ECS and all other services needed to run containers in production, automatically deploying and scaling an ECS cluster and containerized applications. He also shares his experiences and what features are still missing. Filmed at qconlondon.com.

Philipp Garbe works as Lead Software Developer at AutoScout24.

Published in: Technology
  • Be the first to comment

Deliver Docker Containers Continuously on AWS

  1. 1. Deliver Docker Containers Continuously on AWS Philipp Garbe @pgarbe
  2. 2. InfoQ.com: News & Community Site Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations /docker-ecs-aws • Over 1,000,000 software developers, architects and CTOs read the site world- wide every month • 250,000 senior developers subscribe to our weekly newsletter • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • 2 dedicated podcast channels: The InfoQ Podcast, with a focus on Architecture and The Engineering Culture Podcast, with a focus on building • 96 deep dives on innovative topics packed as downloadable emags and minibooks • Over 40 new content items per week
  3. 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon London www.qconlondon.com
  4. 4. So many choices... Amazon ECS Docker Swarm Azure Container Services Cloud Foundry’s Diego https://www.linux.com/news/8-open-source-CONTAINER-ORCHESTRATION-TOOLS-KNOW CoreOS Fleet Google Container Engine Kubernetes Mesosphere Marathon
  5. 5. ● Philipp Garbe ● Lead Developer @Scout24 ● Docker Captain ● Living in Bavaria ● Working in the Cloud About Me
  6. 6. “Hello ECS”
  7. 7. Our first ECS cluster
  8. 8. ECS Cluster: Deployment Options AWS Console AWS CLI ECS CLI CloudFormation Easy to start Yes No Yes No Automation No Yes Yes Yes Infrastructure as Code No No No Yes Auto Scaling Yes Yes No Yes
  9. 9. AWSTemplateFormatVersion: '2010-09-09' Parameters: KeyName: Type: AWS::EC2::KeyPair::KeyName Description: EC2 KeyPair to enable SSH access. ... Resources: ECSCluster: Type: AWS::ECS::Cluster ECSAutoScalingGroup: Type: AWS::AutoScaling::AutoScalingGroup Properties: VPCZoneIdentifier: !Ref ServiceSubnets LaunchConfigurationName: !Ref LaunchConfig MinSize: !Ref ClusterMinSize MaxSize: !Ref ClusterMaxSize LaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Metadata: AWS::CloudFormation::Init: config: commands: 01_add_instance_to_cluster: command: !Sub | #!/bin/bash echo ECS_CLUSTER=${ECSCluster} >> /etc/ecs/ecs.config Properties: ImageId: !FindInMap: [AWSRegionToAMI, Ref: AWS::Region, AMIID] InstanceType: !Ref InstanceType IamInstanceProfile: !Ref EC2InstanceProfile KeyName: !Ref KeyName ... Outputs: ClusterName: Value: !Ref ECSCluster Export: Name: !Sub "${AWS::StackName}-ClusterName"
  10. 10. The first deployment
  11. 11. Container Definition ● Image ● Port mapping ● Mount points ● Network options ● Docker options
  12. 12. Task Definition ● IAM Task Role ● Volumes ● Network Mode ● Task Placement Constraints
  13. 13. Service Description ● Loadbalancer ● AutoScaling ● Deployment Configuration ● Task Placement Strategy
  14. 14. ECS Service: Deployment Options AWS Console AWS CLI ECS CLI CloudFormation Easy to start Yes No Yes No Automation No Yes Yes Yes Configuration as Code No No Partially Yes Auto Scaling Yes Yes No Yes Load Balancer Yes Yes No Yes Task Placement Yes Yes No No *
  15. 15. WebApp: Type: AWS::ECS::Service Properties: Cluster: "Fn::ImportValue": !Sub "${ClusterStack}-ClusterName" TaskDefinition: !Ref TaskDefinition DesiredCount: !Ref DesiredCount DeploymentConfiguration: MaximumPercent: 200 MinimumHealthyPercent: 100 Role: !Ref ServiceAuthRole LoadBalancers: - ContainerName: nginx ContainerPort: 80 TargetGroupArn: !Ref TargetGroup AWSTemplateFormatVersion: '2010-09-09' Parameters: DesiredCount: Type: Number ClusterStack: Type: String Description: Name of the cluster stack ... Resources: TaskDefinition: Type: AWS::ECS::TaskDefinition Properties: TaskRoleArn: !Ref TaskAuthRole ContainerDefinitions: - Name: nginx Image: !Sub nginx:${Version} Cpu: '2048' PortMappings: - ContainerPort: 80 Memory: '1024' Essential: 'true'
  16. 16. Load Balancing
  17. 17. Application Load Balancer (ALB)
  18. 18. Static Port Mapping (ELB)
  19. 19. Dynamic Port Mapping (ALB)
  20. 20. Up & Down
  21. 21. ● Two different kinds of scaling (cluster and service) ○ Cluster: Use cpu / memory reservation metrics ○ Service: Use cpu / memory utilization metrics ● Scale down to save money, but avoid endless-loop ● Scaling takes awhile to take effect ● ASG is not aware of ECS AutoScaling: Conclusion
  22. 22. AutoScaling: Rule of Thumb Threshold = (1 - max(Container Reservation) / Total Capacity of a single Container Instance) * 100 Example: Container instance capacity: 2048 MB Container reservation: 512 MB Threshold = (1 - 512 / 2048) * 100 Threshold = 75%
  23. 23. Node draining ● Finally supported by ECS ● Use Lifecycle Hooks https://aws.amazon.com/blogs/compute/how-to-automate-container-instance-draining-in-amazon-ecs/
  24. 24. Best practices for ECS Cluster ● ASG UpdatePolicy defines deployment strategy ● cfn-init: Ensure Docker and ECS-Agent is running ● Put build no in UserData to enforce new EC2 instances
  25. 25. Volumes
  26. 26. EBS vs EFS
  27. 27. Security
  28. 28. IAM Security Roles ecsAutoScalingRole ecsContainerInstanceRole ecsServiceRole ecsTaskRole ● Read CloudWatch Metrics ● Modify App AutoScaling ● ECR: Get Images ● ECS: De/Register Container Instances ● De/Register Instances with Load Balancer ● Everything your task needs to do https://iam.cloudonaut.io
  29. 29. How to protect yourself EC2 ● Disallow access to metadata service from tasks (containers) iptables --insert FORWARD 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP IAM ● Give the instance role only the credentials it needs (according to aws docs)
  30. 30. ● Re-route call to ECS-Agent ● ECS-Agent gets credentials based on configured TaskRole ● TaskRole needs only one permission: AssumeRole ● X-Acc-Proxy assumes role (Role ARN comes from Docker Label) ● X-Acc-Proxy returns credentials from assumed role Cross Account Proxy
  31. 31. Summary
  32. 32. What did we miss? ● Networking ● Logging ● Monitoring ● CloudWatch Events ● EC2 System Manager parameter store
  33. 33. Where ECS shines… ● Stable Environment ● Catched up with task placement engine ● Native support of IAM ● AutoScaling for hosts and services ● CloudFormation all the way
  34. 34. ● Does not support all the Docker features (e.g. HEALTHCHECK) ● Disconnect between Docker Compose and Task Definition ● Network philosophy is different (Still no SecurityGroups for Containers) ● Volumes still not natively supported (3rd party tools needed) ● It’s not a managed container service And where not...
  35. 35. https://boards.greenhouse.io/scout24 Philipp Garbe http://garbe.io @pgarbe https://github.com/pgarbe
  36. 36. Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/docker- ecs-aws

×