Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to scale your app in minutes with container...

How to scale your app in minutes with containers and AWS ECS

Devoxx 2017 slides: How to scale your app in minutes with containers and AWS ECS

#docker #aws #ecs #scaling #highavailability

Avatar for Arnaud Koster

Arnaud Koster

November 09, 2017
Tweet

Other Decks in Technology

Transcript

  1. @spikeseed @arnaudkoster #Devoxx How to scale your app in minutes

    with containers and AWS ECS Arnaud Koster
  2. @spikeseed @arnaudkoster #Devoxx We should ask ourselves • How to

    install the application? • How to test the application in consistent manner in all the environments? • How should we scale the application and in which conditions? • How to provide high availability?
  3. @spikeseed @arnaudkoster #Devoxx Containers will help us • Containers enable

    consistency, we can run the same image in dev, test and prod • We can spin up new containers in seconds versus days in the past
  4. @spikeseed @arnaudkoster #Devoxx The cloud will help us • Several

    regions/availability zones across the world • A lot of managed services with redundancy, failover, etc.
  5. @spikeseed @arnaudkoster #Devoxx Implement the app the right way The

    application must be ready to scale horizontally Take a look at https://12factor.net Think about this from day-1!
  6. @spikeseed @arnaudkoster #Devoxx EC2 Container Service (ECS) • A container

    orchestration service managed by AWS • Run Docker images from your self-hosted registry, Docker Hub or EC2 Container Registry (ECR) • Well integrated with Application Load Balancer • ECS is able to run Tasks and Services (long lived tasks) • ECS is free, you pay for the underlying resources
  7. @spikeseed @arnaudkoster #Devoxx How does it work? Application Load Balancer

    talk-service speaker-service ECS Agent Amazon ECR talk-service speaker-service ECS Agent EC2 instance /Container Instance EC2 instance /Container Instance Register instance / host port … … Register instance / host port talk-service talk-service
  8. @spikeseed @arnaudkoster #Devoxx Needed steps 1.Dockerize your app 2.Push your

    Docker image on ECR 3.Create an ECS cluster 4.Create a task definition 5.Create an Application Load Balancer and a Target Group 6.Create an ECS Service 7.Scale your cluster and your service
  9. @spikeseed @arnaudkoster #Devoxx Dockerize your app FROM openjdk:8-jre-alpine ADD target/demo-0.0.1-SNAPSHOT.jar

    app.jar ENV JAVA_OPTS="" ENTRYPOINT exec java $JAVA_OPTS - Djava.security.egd=file:/dev/./urandom -jar /app.jar EXPOSE 8080
  10. @spikeseed @arnaudkoster #Devoxx Push your Docker image on ECR AWS

    gives you the steps to execute: 1. Retrieve the docker login command that you can use to authenticate your Docker client to your registry: aws ecr get-login --no-include-email --region eu-west-1 2. Build your Docker image using the following command. For information on building a Docker file from scratch see the instructions here. You can skip this step if your image is already built: docker build -t talk-service . 3. After the build completes, tag your image so you can push the image to this repository: docker tag talk-service:latest 340754841610.dkr.ecr.eu-west- 1.amazonaws.com/talk-service:latest 4. Run the following command to push this image to your newly created AWS repository: docker push 340754841610.dkr.ecr.eu-west-1.amazonaws.com/talk-service:latest
  11. @spikeseed @arnaudkoster #Devoxx Create an ECS cluster 1.Create a security

    group 2.Create an empty cluster • Select EC2 instance type • Choose the number of instances • Choose a key pair • Select a VPC and the subnets
  12. @spikeseed @arnaudkoster #Devoxx Create a task definition { "family": "talk-service",

    "containerDefinitions": [ { "name": "web", "image": "340754841610.dkr.ecr.eu-west-1.amazonaws.com/talk- service:latest", "cpu": 128, "memoryReservation": 128, "portMappings": [ { "containerPort": 8080, "protocol": "tcp" } ], "command": [], "essential": true } ] }
  13. @spikeseed @arnaudkoster #Devoxx Create an Application Load Balancer and a

    Target Group 1. Create an ALB: • Listening on port 80 • VPC/subnets 2. Attach this ALB to a security group: • 0.0.0.0/0 and ::/0 on port 80 3. Allow the traffic from the ALB’s security group to the cluster’s security group 4. Create the target group for the application • Listening on port 80 • Configure health check (/health from Spring Boot)
  14. @spikeseed @arnaudkoster #Devoxx Create an ECS Service { "cluster": "conference-cluster",

    "serviceName": "talk-service-ecs", "taskDefinition": "talk-service", "loadBalancers": [ { "targetGroupArn": "arn:aws:elasticloadbalancing:eu-west- 1:340754841610:targetgroup/talkServiceTargetGroup/a9398b179c9b718a", "containerName": "web", "containerPort": 8080 } ], "desiredCount": 4, "role": "ecsServiceRole" }
  15. @spikeseed @arnaudkoster #Devoxx Scale your cluster and your service •

    ECS should scale based on 2 variables: • The number of EC2 instances • The number of running tasks on these EC2 instances
  16. @spikeseed @arnaudkoster #Devoxx Conclusion • Consistency, Scalability and High Availability

    ✓ • Check the details in my blog post: https://goo.gl/3Gfk8b