Top Banner
Introduction to Amazon EC2 Container Service and setting up build pipeline with ECS and Jenkins Swapnil Dahiphale DevOps Engineer, WhiteHedge Technologies
41

EC2 Container Service

Jan 11, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: EC2 Container Service

Introduction  to  Amazon  EC2  Container  Service and  setting  up  build  pipeline  with  

ECS  and  Jenkins

Swapnil DahiphaleDevOps  Engineer,  WhiteHedge  Technologies

Page 2: EC2 Container Service

Agenda

• Containers• Orchestration  • Why  ECS?• What  is  ECS?• Key  Components• Typical  user  workflow• Build  pipeline  with  Jenkins  and  ECS

Page 3: EC2 Container Service

Containers

“au tomates  the  d ep l oyment  of  an y    appl ication  as   a   l ightweight,  portable,     sel f-­‐sufficient containerthat  wi l l  run  vi rtual lyan ywhere”

Page 4: EC2 Container Service

What  are containers?

OS  virtualization    

Process isolation    

Automation    

ImagesServer

Guest OS

Bins/Libs Bins/Libs

App2App1

Page 5: EC2 Container Service

Why  use Docker?

With Docker we can solve many problems

• “it works on my machine”• reducing build & deploy time• Infrastructure   configuration –automation!• Libs  dependency hell• Cost  control  and granularity

Page 6: EC2 Container Service

A  container pipeline

Page 7: EC2 Container Service

A  container pipelineIT Operations

BaseImage

PatchesUtilities

Page 8: EC2 Container Service

A  container pipelineIT Operations

BaseImage

PatchesUtilities

Ruby

Redis

Logger

Page 9: EC2 Container Service

A  container pipelineIT Operations Developer

BaseImage

PatchesUtilities

Ruby

Redis

Logger

App

Page 10: EC2 Container Service

A  container pipeline

BaseImage

PatchesUtilities

IT Operations Developer

Ruby

Redis

Logger

App

Page 11: EC2 Container Service

Orchestration!

Page 12: EC2 Container Service

Orchestration  is  a  mean  to  Automate  Manual  Process  

Orchestration

Page 13: EC2 Container Service

Why  Orchestration?

• Microservice  Architectures• Fault  tolerance  /  High  Availability• Scalability• Resource  Utilization

Page 14: EC2 Container Service

Orchestration  Tools

• Kubernetes• Docker  Swarm• Amazon  EC2  Container  Service

Page 15: EC2 Container Service

Why  EC2  Container  Service ?

Page 16: EC2 Container Service
Page 17: EC2 Container Service
Page 18: EC2 Container Service

What  is  ECS?

Building  Block  Service

Page 19: EC2 Container Service

What  is  ECS?

Easily  Manage  Clusters  for  Any Scale

• Nothing  to run• Complete state• Control  and monitoring• Scale

ECS  List*  and  Describe*  APIactions

Page 20: EC2 Container Service

What  is  ECS?

Flexible  Container Placement

• Applications• Batch jobs• Multiple schedulers

Page 21: EC2 Container Service

What  is  ECS?

Designed  for  use  with  other  AWS services

• Virtual  Private Cloud• Elastic  Load Balancing• Elastic  Block Store• IAM• CloudTrail

Page 22: EC2 Container Service

What  is  ECS?

Performance  at  scale

Page 23: EC2 Container Service

What  is  ECS?

Secure

Your  containers,Your  instances

Page 24: EC2 Container Service

What  is  ECS?

Extensible

• ComprehensiveAPIs• Open  sourceagent• Customschedulers

Page 25: EC2 Container Service

Key  Components

Tasks

Containers

Clusters

Container  Instances

Page 26: EC2 Container Service

Key  Components:  Container  Instances

Amazon  EC2  instances

Docker  daemon

Amazon  ECS  agent

Page 27: EC2 Container Service

Key  Components:  Clusters

Regional

Resource  pool

Grouping  of  Container  Instances

Start  empty,  dynamically  scalable

Page 28: EC2 Container Service

Key  Components:  Tasks

Unit  of  work

Grouping  of  related  containers

Run  on  Container  Instances

Page 29: EC2 Container Service

Key  components:  task definitions{

"environment": [],"name": "simple-demo","image": "my-demo", "cpu": 10,"memory": 500, "portMappings": [

{"containerPort": 80,"hostPort": 80

}],"mountPoints": [

{"sourceVolume": "my-vol", "containerPath":"/var/www/my-

vol"}

],"entryPoint": [

"/usr/sbin/apache2", "-D","FOREGROUND"

],"essential": true

},

{"name": "busybox","image":"busybox", "cpu": 10,"memory": 500, "volumesFrom": [{"sourceContainer": "simple-demo"}],"entryPoint"

: [ "sh","-c"

],"command": [

"/bin/sh -c \"while true; do/bin/date > /var/www/my-vol/date; sleep 1;done\""

],"essential": false

}

Page 30: EC2 Container Service

{"environment": [],"name": "simple-demo","image": "amazon/amazon-ecs-sample", "cpu": 10,"memory": 500, "portMappings":[

{"containerPort": 80,"hostPort": 80

}],"mountPoints": [

{"sourceVolume": "my-vol", "containerPath":"/var/www/my-

vol"}

],"entryPoint": [

"/usr/sbin/apache2", "-D","FOREGROUND"

],"essential": true

},

Key  components:  task definitions

Essential  to  our task

10  CPU  units  (1024  is  full  CPU),    500  megabytes  of memory

Expose  port  80  in containerto  port  80  on host

Create  and  mount volumes

Page 31: EC2 Container Service

{

Key  components:  task definitions"name": "busybox","image": "busybox",    "cpu": 10,"memory":  500,    "volumesFrom": [{

"sourceContainer": "simple-­‐demo"}],

"entryPoint": [    "sh","-­‐c"

],"command": [

"/bin/sh   -­‐c  \"while  true; do/bin/date  >  /var/www/my-­‐vol/date;  sleep  1; done\""

],"essential": false

}

[{"image": "tutum/wordpress-stackable", "name": "wordpress","cpu": 10,"memory": 500,"essential": true, "links": ["db"

],"entryPoint": [ "/bin/sh","-c"

],"environment": […

],"portMappings": [{"containerPort": 80,"hostPort": 80

}]

},]

From  Docker Hub

Mount  volume  from  other container

Command  to exec

Page 32: EC2 Container Service

Typical  user workflowI  want  to  run  aservice

Page 33: EC2 Container Service

Typical  user workflow

Run Instances AmazonEC2

Use  custom  AMI  with    Docker  support  and    ECS  Agent. Instances    will  register  with    default cluster.

Page 34: EC2 Container Service

Typical  user workflow

Create  Task Definition

Declare resourcerequirements forcontainers

Shared  Data Volume

Node.jsApp Time  of day    App

Page 35: EC2 Container Service

Typical  user workflow

Create Service

Declare resourcerequirements forservice

Shared  Data Volume

Node.jsApp Time  of day    App

Elastic    Load    

Balancing

X 5

Page 36: EC2 Container Service

Typical  user workflow

Describe Service

Page 37: EC2 Container Service

Demo

Page 38: EC2 Container Service

Build  Pipeline  with  ECS  and  Jenkins

Page 39: EC2 Container Service

Continuous  delivery  with Jenkins

Build image

Push image

Update service

Page 40: EC2 Container Service

Q&A

Page 41: EC2 Container Service

Thank  You