auto scaling with ruby, aws, jenkins and redis

67
Auto Scaling with Ruby, AWS, Jenkins and Redis

Upload: yi-hsuan-jeddie-chuang

Post on 14-Jul-2015

1.077 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Auto scaling with Ruby, AWS, Jenkins and Redis

Auto Scaling

with

Ruby, AWS, Jenkins

and Redis

Page 2: Auto scaling with Ruby, AWS, Jenkins and Redis

hello!

I am

JeDDie

A software engineer. A Rails Girls volunteer.

Page 3: Auto scaling with Ruby, AWS, Jenkins and Redis

Auto Scaling

with

Ruby, AWS, Jenkins

and Redis

Page 4: Auto scaling with Ruby, AWS, Jenkins and Redis

1.

Auto Scaling?

Scalability.

Page 5: Auto scaling with Ruby, AWS, Jenkins and Redis

“Methods of adding more resources for a particular

application fall into two broad categories:horizontal and vertical scaling.

http://en.wikipedia.org/wiki/ScalabilityMichael, Maged; Moreira, Jose E.; Shiloach, Doron; Wisniewski, Robert W. (March 26, 2007).

"2007 IEEE International Parallel and Distributed Processing Symposium"

Page 6: Auto scaling with Ruby, AWS, Jenkins and Redis

Scale Vertically

▸ Scale up and down

about SCALABILITY

Scale Horizontally

▸ Scale out

scale up

scale down

1

4

Page 7: Auto scaling with Ruby, AWS, Jenkins and Redis

Okay,

and WHY?

needs auto scaling

Page 8: Auto scaling with Ruby, AWS, Jenkins and Redis

about

our office

❤ Taiwan

Page 9: Auto scaling with Ruby, AWS, Jenkins and Redis

Place your screenshot hereContent Matters

When the live show attracts people, they will become audience right away.

Page 10: Auto scaling with Ruby, AWS, Jenkins and Redis

柯P:一個更好的台北2014-11-29

158,157 clicks

10,400 ccu

Page 11: Auto scaling with Ruby, AWS, Jenkins and Redis

2.

Amazon Web Services

What we need for auto scaling.

Page 12: Auto scaling with Ruby, AWS, Jenkins and Redis

AWS

require “aws”

auto_scaling = ec2 + cli + elb + elasti_cache

Page 13: Auto scaling with Ruby, AWS, Jenkins and Redis

3.

Amazon EC2

Elastic Compute Cloud

Page 14: Auto scaling with Ruby, AWS, Jenkins and Redis

Amazon EC2

▸ Amazon Elastic Compute Cloud○ “A web service that provides resizable compute

capacity in the cloud”○ “Designed to make web-scale cloud computing

easier for developers”■ Scale up/down; start, stop, terminate...etc.

EASY management with a great UI.

Page 15: Auto scaling with Ruby, AWS, Jenkins and Redis

AMI

▸ Amazon Machine Images○ “A template for the root volume for the instance

(for example, an operating system, an application server, and applications)”

A script of an instance.

Page 16: Auto scaling with Ruby, AWS, Jenkins and Redis

4.

AWS CLI

Command Line Interface

Page 18: Auto scaling with Ruby, AWS, Jenkins and Redis

Process of Launching Instance

Launch instance using image Allocate IP Associate IP

with instance

Page 19: Auto scaling with Ruby, AWS, Jenkins and Redis

`ec2-run-instances #{AMI_ID} #{REGION}#{GROUP} #{SUBNET} #{INSTANCE_TYPE}

#{BLOCK_DEVICE_MAPPING}`

Launch an Instance Using an Image.

launch

instanceImage

ID

security

group

small?

large?

additional

store volume

Page 20: Auto scaling with Ruby, AWS, Jenkins and Redis

ec2-run-instances

ec2-run-instances ami-1a2b3c4d -s subnet-1a2b3c4d -t c1.medium

OUTPUT>RESERVATION r-1a2b3c4d 111122223333INSTANCE i-1a2b3c4d ami-1a2b3c4d pending

c1.medium YYYY-MM-DDTHH:MM:SS+0000 10.0.0.146 …

from Amazon doc

Page 21: Auto scaling with Ruby, AWS, Jenkins and Redis

`ec2-allocate-address -d vpc #{REGION}`

Allocate an Elastic IP for use.

virtual private cloud

Page 22: Auto scaling with Ruby, AWS, Jenkins and Redis

ec2-allocate-address

ec2-allocate-address -d vpc

OUTPUT>ADDRESS 198.51.100.1 vpc eipalloc-5723d13e

from Amazon doc

Page 23: Auto scaling with Ruby, AWS, Jenkins and Redis

`ec2-associate-address#{ALLOCATION_ID} #{INSTANCE_ID} #{REGION}`

Associates an Elastic IP with an Instance.

bind IP and

instance

elastic ip

Page 24: Auto scaling with Ruby, AWS, Jenkins and Redis

ec2-associate-address

ec2-associate-address -a eipalloc-5723d13e -i i-4fd2431a

OUTPUT>ADDRESS i-43a4412a eipalloc-5723d13e

eipassoc-fc5ca095

from Amazon doc

Page 25: Auto scaling with Ruby, AWS, Jenkins and Redis

Do all

in One Step

?

Page 26: Auto scaling with Ruby, AWS, Jenkins and Redis

Do All in One

▸ Pros○ Simple flow

▸ Cons○ Legacy > 5 mins

Facts that matter

Break Things Down

▸ Pros○ Flexible to handle

▸ Cons○ Different entries by

time

It takes 5 minutes to run an instance up

process

launch + IP

go online

process

Page 27: Auto scaling with Ruby, AWS, Jenkins and Redis

Process of Terminating Instance

Disassociate IP from instance Release IP Terminate

instance

Page 28: Auto scaling with Ruby, AWS, Jenkins and Redis

`ec2-disassociate-address #{ASSOCIATION_ID} #{REGION}`

Disassociates Elastic IP from Instance.

the link

ec2-disassociate-address -a eipassoc-048c746d

OUTPUT>ADDRESS eipassoc-048c746d

example from Amazon doc

Page 29: Auto scaling with Ruby, AWS, Jenkins and Redis

`ec2-release-address #{ASSOCIATION_ID} #{REGION}`

Release Elastic IP.

ec2-release-address -a eipassoc-048c746d

OUTPUT>ADDRESS eipassoc-048c746d

example from Amazon doc

Page 30: Auto scaling with Ruby, AWS, Jenkins and Redis

`ec2-terminate-instances #{INSTANCE_ID}#{REGION}`

Shutdown Instance.

PROMPT> ec2-terminate-instances i-1a2b3c4d

OUTPUT>INSTANCE i-1a2b3c4d running shutting-down

example from Amazon doc

Page 31: Auto scaling with Ruby, AWS, Jenkins and Redis

5.

AWS ELB

Elastic Load Balancing

Page 32: Auto scaling with Ruby, AWS, Jenkins and Redis

AWS ELB

▸ Elastic Load Balancing○ “Automatically distributes incoming application

traffic across multiple Amazon EC2 instances in the cloud.”

Traffic-monitoring UI and the metrics.

Icon made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Page 33: Auto scaling with Ruby, AWS, Jenkins and Redis

`elb-register-instances-with-lb #{LOAD_BALANCER} #{INSTANCE_ID} #{REGION}

#{CREDENTIAL_FILE}`

Make Load Balancer Know Instance.

Page 34: Auto scaling with Ruby, AWS, Jenkins and Redis

elb-register-instance-with-lb

aws elb register-instances-with-load-balancer --load-balancer-name my-test-loadbalancer --instances i-4e05f721

OUTPUT>

{ "Instances": [ {"InstanceId": "i-315b7e51"}, {"InstanceId": "i-4e05f721"} ]}

from Amazon doc

Page 35: Auto scaling with Ruby, AWS, Jenkins and Redis

`elb-deregister-instances-with-lb #{LOAD_BALANCER} #{INSTANCE_ID} #{REGION}

#{CREDENTIAL_FILE}`

Cut Instance out from Load Balancer.

aws elb register-instances-with-load-balancer --load-balancer-name my-test-loadbalancer --instances i-4e05f721

OUTPUT>

{"Instances": [{"InstanceId": "i-315b7e51"}]}

from Amazon doc

Page 36: Auto scaling with Ruby, AWS, Jenkins and Redis

`aws elb describe-instance-health #{LOAD_BALANCER} #{REGION}`

Returns the current state of the instances

registered with the specified load balancer.

Page 37: Auto scaling with Ruby, AWS, Jenkins and Redis

describe-instance-health

aws elb describe-instance-health --load-balancer-name MyHTTPSLoadBalancer

OUTPUT>

{ "InstanceStates": [ {"InstanceId": "i-cb439ec2", "ReasonCode": "N/A", "State": "InService", "Description": "N/A"} ]}

from Amazon doc

Page 38: Auto scaling with Ruby, AWS, Jenkins and Redis

`mon-get-stats #{METRIC} #{NAMESPACE}#{STATISTICS} #{REGION} #{DIMENSIONS}

#{CREDENTIAL_FILE}`

Get time-series data for one or more statistics

of a given Metric.

get time-series

data

requestCount,

HTTPCode_Backend_2XX, ...

aws/elb

sum

lb name

Page 39: Auto scaling with Ruby, AWS, Jenkins and Redis

mon-get-stats

mon-get-stats RequestCount --statistics "Sum" --namespace "AWS/ELB"

OUTPUT>

2015-01-29 12:01:00 687.0 Count

2015-01-29 12:02:00 753.0 Count

2015-01-29 12:03:00 836.0 Count

from Amazon doc

Page 40: Auto scaling with Ruby, AWS, Jenkins and Redis

Elements

ELB

monitor traffic

EC2

launch or terminate instance

ElastiCache

trackinstance status

Page 41: Auto scaling with Ruby, AWS, Jenkins and Redis

6.

Amazon ElastiCache

Redis

Page 42: Auto scaling with Ruby, AWS, Jenkins and Redis

Amazon ElastiCache

▸ Amazon ElastiCache○ “makes it easy to deploy, operate, and scale an

in-memory cache in the cloud”

Redis, a key-value database.

Page 43: Auto scaling with Ruby, AWS, Jenkins and Redis

Redis

“Redis is an open source, BSD licensed, advanced key-value

cache and store. ”- http://redis.io

Different data structures:strings, hashes, lists, sets, ...

Icon made by Carlos Prioglio from www.iconfinder.com is licensed under CC BY-NC-SA 3.0

Page 44: Auto scaling with Ruby, AWS, Jenkins and Redis

7.

Auto Scaling!

Automation.

Page 45: Auto scaling with Ruby, AWS, Jenkins and Redis

Auto Scaling

Icons made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Page 46: Auto scaling with Ruby, AWS, Jenkins and Redis

Let’s auto scale!

Icon made by SimpleIcon from www.flaticon.com is licensed under CC BY 3.0

Page 47: Auto scaling with Ruby, AWS, Jenkins and Redis

A Robot’s Day

Its name is Bee!

Icon made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Page 48: Auto scaling with Ruby, AWS, Jenkins and Redis

Monitor Traffic

▸ CLI○ elb-register-instances-with-lb○ mon-get-stats

Page 49: Auto scaling with Ruby, AWS, Jenkins and Redis

Decide a Threshold

▸ Observe what has happened

time

request

Page 50: Auto scaling with Ruby, AWS, Jenkins and Redis

The Basic Process

▸ Basic actions○ ec2-run-instances○ ec2-allocate-address○ ec2-associate-address○ elb-register○ elb-deregister○ ec2-disassociate-address○ ec2-release-address○ ec2-terminate-instances

Page 51: Auto scaling with Ruby, AWS, Jenkins and Redis

Watch for Status

▸ Now what should be done?○ Add/remove instance

■ Number of online-servers■ Traffic and threshold

○ Register/deregister instance with load balancer○ Update instance status

■ pending / Initializing / running / stop / problem○ White List○ Limitation

■ Time■ Scaling

Icon made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Page 52: Auto scaling with Ruby, AWS, Jenkins and Redis

Track Things Down

▸ Online instances▸ Waken instances▸ Problem instances

Redis data type: List.i-abcde01

i-bcdef02

i-cdefg03

Page 53: Auto scaling with Ruby, AWS, Jenkins and Redis

Track Things Down

▸ Instance information▸ The timestamp of the last instance

initialized

Redis data type: String.i-abcde01: "{id: i-abcde01, status: initializing, private_ip: 192.168.0.1, public_ip: 54.12.23.34, created_at: 2015/01/20 14:03:00}"

Page 54: Auto scaling with Ruby, AWS, Jenkins and Redis

Release

Page 55: Auto scaling with Ruby, AWS, Jenkins and Redis

8.

Deployment

Let’s meet other robots!

Page 57: Auto scaling with Ruby, AWS, Jenkins and Redis

Always put the NEWEST service online.

Icon made by OCHA , icon made by Freepik, icon made by Sarfraz Shoukat from www.flaticon.com is licensed under CC BY 3.0

Icon made by Charles Lowell and Frontside from jenkins-ci.org is licensed under CC BY-SA 3.0

Page 58: Auto scaling with Ruby, AWS, Jenkins and Redis

with Jenkins

Auto Scaling + Deployment

Page 59: Auto scaling with Ruby, AWS, Jenkins and Redis

New pre and post processes.

Original

Deployment

Get

servers’

IP

Build Image

Page 60: Auto scaling with Ruby, AWS, Jenkins and Redis

Get

servers’

IP

`aws ec2 describe-instances #{REGION} --filters "Name=instance-state-name,Values=running" "Name=instance.group-name,Values=FrontEnd" "Name=tag-value,Values=FrontEnd Production*" "Name=ip-address,Values=*"`

RESERVATION r-1a2b3c4d 111122223333INSTANCE i-1a2b3c4d ami-1a2b3c4d running my-key-pair 0 m1.small YYYY-MM-DDTHH:MM:SS+0000 us-west-2b windows monitoring-disabled 50.112.172.209 10.0.0.167 vpc-1a2b3c4dsubnet-1a2b3c4d ebs hvm xen ABCDE1234567890123sg-1a2b3c4d default falseBLOCKDEVICE /dev/sdb vol-1a2b3c4d YYYY-MM-DDTHH:MM:SS.SSSZtrueNIC eni-1a2b3c4dsubnet-1a2b3c4d vpc-1a2b3c4d111122223333in-use10.0.1.167 trueNICATTACHMENT eni-attach-1a2b3c4d 0 attached YYYY-MM-DDTHH:MM:SS+0000trueGROUP sg-1a2b3c4d my-security-groupPRIVATEIPADDRESS 10.0.1.167PRIVATEIPADDRESS 10.0.1.12TAG instance i-1a2b3c4d Name Windows

from Amazon doc

Page 61: Auto scaling with Ruby, AWS, Jenkins and Redis

Build Image

`ec2-create-image #{INSTANCE_ID} #{NAME} #{DESCRIPTION} --no-reboot #{REGION}`

ec2-create-image i-10a64379 --name "Standard Web Server" --description "Standard web server AMI"

OUTPUT>

IMAGE ami-4fa54026

from Amazon doc

Page 62: Auto scaling with Ruby, AWS, Jenkins and Redis

Do we solve it? NOT yet!

Page 63: Auto scaling with Ruby, AWS, Jenkins and Redis

Good communication matters!

icons made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Page 64: Auto scaling with Ruby, AWS, Jenkins and Redis

Happy Auto Scaling!Icon made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Page 65: Auto scaling with Ruby, AWS, Jenkins and Redis

Join us!

https://livehouse.in/recruit

Page 66: Auto scaling with Ruby, AWS, Jenkins and Redis

Thanks!

anyquestions

?

You can find me [email protected]

Page 67: Auto scaling with Ruby, AWS, Jenkins and Redis

Credits

Special thanks to all the people who made and released these awesome resources for free:▸ Busy Icons by Olly Holovchenko▸ Presentation template by SlidesCarnival▸ Photographs by Unsplash▸ Paper backgrounds by SubtlePatterns▸ Other icons are from

▸ http://www.freepik.com▸ http://www.flaticon.com▸ https://livehouse.in▸ http://jenkins-ci.org