wayin devops-2013

42
DevOps at Wayin Orchestration with AWS Cloud Formation David M. Johnson Software Developer - Wayin, Inc. Friday, June 21, 13

Upload: david-m-johnson

Post on 11-May-2015

881 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Wayin devops-2013

DevOps at WayinOrchestration with AWS Cloud Formation

David M. JohnsonSoftware Developer - Wayin, Inc.

Friday, June 21, 13

Page 2: Wayin devops-2013

Agenda

•What is Cloud Orchestration

• Quick intro to Wayin Hub

• Wayin Hub deployment & application architecture

• How we scale, deploy and do backups

• About Cloud Formation Templates

• About vendor lock-in

• Designing for orchestration

Friday, June 21, 13

Page 3: Wayin devops-2013

“Orchestration describes the automated arrangement, coordination, and management of complex computer systems, middleware, and services.

It is often discussed as having an inherent intelligence or even implicitly autonomic control, but those are largely aspirations or analogies rather than technical descriptions.”

http://en.wikipedia.org/wiki/Orchestration_(computing)

Friday, June 21, 13

Page 5: Wayin devops-2013

Cloud Orchestration is...

Automating the infrastructure needed to provide a computing service so that resources are automatically allocated and de-allocated to meet changing demand

Friday, June 21, 13

Page 6: Wayin devops-2013

The Orchestra Analogy

Friday, June 21, 13

Page 7: Wayin devops-2013

Benefits

•Saves money

•Saves time

•Repeatable, version-able process

•Less human intervention

•Fewer stupid mistakes

Friday, June 21, 13

Page 8: Wayin devops-2013

Agenda

• What is Cloud Orchestration

•Quick intro to Wayin Hub

• Wayin Hub deployment & application architecture

• How we scale, deploy and do backups

• About Cloud Formation Templates

• About vendor lock-in

• Designing for orchestration

Friday, June 21, 13

Page 9: Wayin devops-2013

Friday, June 21, 13

Page 10: Wayin devops-2013

Friday, June 21, 13

Page 11: Wayin devops-2013

Friday, June 21, 13

Page 12: Wayin devops-2013

Friday, June 21, 13

Page 13: Wayin devops-2013

Friday, June 21, 13

Page 14: Wayin devops-2013

Friday, June 21, 13

Page 15: Wayin devops-2013

Friday, June 21, 13

Page 16: Wayin devops-2013

Agenda

• What is Cloud Orchestration

• Quick intro to Wayin Hub

•Wayin Hub deployment & app architecture

• How we scale, deploy and do backups

• About Cloud Formation Templates

• About vendor lock-in

• Designing for orchestration

Friday, June 21, 13

Page 17: Wayin devops-2013

Glossary• EC2 - server virtualization

• EBS - mountable block storage

• ELB - load balancer

• R53 - domain name services (DNS)

• S3 - file / bucket storage service

• CloudFront - content distribution network (CDN)

• Autoscale - automatically stop & start servers

• CloudWatch / Cloud Alarms - monitoring & triggering

• Security Group - restrict port access on group of instances

• SQS - Simple Queuing Service

Friday, June 21, 13

Page 18: Wayin devops-2013

Application Architecture

Browser

Front end

HTML5jQuery

Backbone

Ubuntu

Back end

Java, JettyJerseyGuice

RESTHTTP

Ubuntu

Cassandra

Redis

Memcache

Queue Service

Twitter Feeds Other Soc. Nets

Friday, June 21, 13

Page 19: Wayin devops-2013

Ubuntu

Jenkins

API Security Group

S3

R53CloudFront

ELB

EC2Browser

Front end

DB Security Group

EBS

SQS

TwitterFeeds

Tracker Security Group

Deployment Architecture

Cloud Formation

// CFN template { "Parameters": {

}, "Mappings": {

}, "Resources": {

}}

Friday, June 21, 13

Page 20: Wayin devops-2013

Cloud Formation

“An easy way to create and manage a collection of related AWS resources, provisioning and updating them in an orderly and predictable fashion.

You can use AWS CloudFormation’s sample templates or create your own. Once deployed, you can modify and update the AWS resources in a controlled and predictable way allowing you to version control your AWS infrastructure in the same way as you version control your software.

You can deploy and update a template and its associated collection of resources (called a stack) via the AWS Management Console, CloudFormation command line tools or APIs. CloudFormation is available at no additional charge, and you pay only for the AWS resources needed to run your applications.”

Friday, June 21, 13

Page 21: Wayin devops-2013

Agenda

• What is Cloud Orchestration

• Quick intro to Wayin Hub

• Wayin Hub deployment & application architecture

•How we scale, deploy and do backups

• About Cloud Formation Templates

• About vendor lock-in

• Designing for orchestration

Friday, June 21, 13

Page 22: Wayin devops-2013

Separate auto-scale groups

Ubuntu

API server

WAR

Jetty

Ubuntu

API server

WAR

Jetty

Ubuntu

API server

WAR

Jetty

Min: 3Max: 9

Scale up (quickly):CPU > X% for Y minutes

Scale down (slowly):CPU < A% for B minutes

Ubuntu

Cassandra

Redis

Memcache

DB serverUbuntu

Cassandra

Redis

Memcache

DB server

Min: 2Max: 2

We decide when to scaleup and scale down our DB server instances

Ubuntu

Tracker

WAR

Jetty

Ubuntu

Tracker

WAR

Jetty

Ubuntu

Tracker

WAR

Jetty

Min: 2Max: 20

Scale up (quickly):Queue has > X messages for Y minutes

Scale down (slowly):Queue has < X message for Y minutes

Friday, June 21, 13

Page 23: Wayin devops-2013

CFN Launches new API server instances

1

Self-configuring API servers

DB Security Group

S3 ELBCloudInit script downloads the

deployment bundle2

CloudInit scripts find DB servers by Security Group, starts Jetty

3

CloudInit scripts put server into ELB rotation

4

API Security Group

CFNCloud Watch

Friday, June 21, 13

Page 24: Wayin devops-2013

Self-configuring DB servers

DB Security Group

S3

CloudInit scripts finds other DB servers by Server Group3

CloudInit scripts download latest

deployment bundle

2Human runs the command to increase

DB servers by one

1

Ubuntu

New DB server

New Cassandra node joins cluster when ready7

CFN

CloudInit scripts write Memcache config, start it4

MemcacheCloudInit scripts write Redis config, assume first server is master, start it5

RedisCloudInit scripts write Cassandra config, start it6

Cassandra

Friday, June 21, 13

Page 25: Wayin devops-2013

Automated deployment

API Security Group

GitDeveloper merges code into deployment branch 1

Developer kicks off Jenkins build 2

S3

Jenkins copies bundle to S3 bucket 3

Developer kicks off deployment build 4

Jenkins runs deploy command

via SSH

5

On each server the script runs locally, downloads and installs the bundle

6

Ubuntu

Jenkins

Tracker Security Group

Friday, June 21, 13

Page 26: Wayin devops-2013

Incremental backups copied to S3 bucket5

Automated Backups

S3

Jenkins runs daily backup job

1

Backup script creates EBS snapshot 3

DB Security Group

Cronjob kicks off incremental backups4

Cassandra snapshot backups happen simultaneously

2

Ubuntu

Jenkins

EBS

Friday, June 21, 13

Page 27: Wayin devops-2013

Agenda

• What is Cloud Orchestration

• Quick intro to Wayin Hub

• Wayin Hub deployment & application architecture

• How we scale, deploy and do backups

•About Cloud Formation Templates

• About vendor lock-in

• Designing for orchestration

Friday, June 21, 13

Page 28: Wayin devops-2013

CFN Template skeleton{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Example stack",

"Parameters": {

},

"Mappings": {

},

"Resources": {

}}

Friday, June 21, 13

Page 29: Wayin devops-2013

CFN Parameters{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "WayinHub Three Server-type Prod Stack",

"Parameters": {

"DnsName" : { "Description" : "DNS name to be created", "Type" : "String", "Default": "stack-test" },

"DnsDomain" : { "Description" : "DNS domain to be used", "Type" : "String", "Default": "twt.pl" },

"KeyPair" : { "Description" : "EC2 Key Pair to allow SSH...", "Type" : "String", "Default": "wayin" },

Friday, June 21, 13

Page 30: Wayin devops-2013

CFN Parameters "ReleaseBucket" : { "Description" : "S3 Bucket of release bundle", "Type" : "String", "Default": "hub-deployment-release" }, "ApiMinServers" : { "Description" : "Minimum number of API servers", "Type" : "Number", "Default": "2", "MinValue": "2" },

"ApiMaxServers" : { "Description" : "Maximum number API servers", "Type" : "Number", "Default": "5", "MinValue": "2" },

"ApiInstanceType": { "Description": "EC2 instance type for API servers", "Type": "String", "Default": "m1.large", "AllowedValues": ["m1.xlarge", "m3.xlarge"], "ConstraintDescription": "must be a valid EC2 type." },

Friday, June 21, 13

Page 31: Wayin devops-2013

CFN Mappings

"Mappings": { "AWSRegionArch2AMI": { "us-east-1": { "64": "ami-e864da81" }, "us-west-2": { "64": "ami-50f97060" } }, "TwoAZs": { "us-east-1": { "AZ1" : "us-east-1a", "AZ2" : "us-east-1b" }, "us-west-2": { "AZ1" : "us-west-2a", "AZ2" : "us-west-2b" } } },

Friday, June 21, 13

Page 32: Wayin devops-2013

CFN Resources "Resources": { "DbAutoScalingLaunchConfiguration": { "Type": "AWS::AutoScaling::LaunchConfiguration", }, "DbAutoScalingGroup": { "Type": "AWS::AutoScaling::AutoScalingGroup", }, "ApiAutoScalingLaunchConfiguration": { "Type": "AWS::AutoScaling:: LaunchConfiguration", }, "ApiAutoScalingGroup": { "Type": "AWS::AutoScaling::AutoScalingGroup", }, "ApiServerScaleUpPolicy" : { "Type" : "AWS::AutoScaling::ScalingPolicy", }, "ApiServerScaleDownPolicy" : { "Type" : "AWS::AutoScaling::ScalingPolicy", }, "CPUAlarmHigh": { }, "CPUAlarmLow": { },

Friday, June 21, 13

Page 33: Wayin devops-2013

CFN Resources"ApiAutoScalingLaunchConfiguration": { "Type": "AWS::AutoScaling::LaunchConfiguration", "Properties": { "UserData": { "Fn::Base64" : { "Fn::Join": [ "", [ "#!/bin/bash -ex\n",

"# Log all output from this script\n", "exec >/var/log/wayin-bootstrap.log 2>&1\n",

"# Expose various environmental variables, etc.\n", "cat >/etc/profile.d/wayin-env.sh <<EOF\n", "export ELB_NAME=", { "Ref" : "ApiElasticLoadBalancer" }, "\n", "export EC2_REGION=", { "Ref" : "AWS::Region" }, "\n", "export DNS_NAME=", { "Ref" : "DnsName" }, "\n", "export DNS_DOMAIN=", { "Ref" : "DnsDomain" }, "\n", "EOF\n", "# Install various packages\n", "apt-get update\n", "apt-get -y install s3cmd\n", "\n", "# Download our application files\n", "cd /usr/share/wayinhub\n", "s3cmd --config=/etc/s3cfg get s3://",{"Ref":"ReleaseBucket"},"/twithub.tgz\n", "tar xf twithub.tgz\n", "rm -fr twithub.tgz\n", "cd ./init_instance\n", "sh ./init_api_server.sh\n" ]]} },

Friday, June 21, 13

Page 34: Wayin devops-2013

CFN Console

Friday, June 21, 13

Page 35: Wayin devops-2013

Agenda

• What is Cloud Orchestration

• Quick intro to Wayin Hub

• Wayin Hub deployment & application architecture

• How we scale, deploy and do backups

• About Cloud Formation Templates

•About vendor lock-in

• Designing for orchestration

Friday, June 21, 13

Page 36: Wayin devops-2013

Lock-in in automation

• Cloud Formation itself is lock-in

• Plenty of AWS dependencies in our:

• Instance init scripts

• Deployment scripts

• Backup scripts

Friday, June 21, 13

Page 37: Wayin devops-2013

No lock-in in app code

• Bulk of our code is in our application

• AWS dependencies are pluggable

Friday, June 21, 13

Page 38: Wayin devops-2013

Agenda

• What is Cloud Orchestration

• Quick intro to Wayin Hub

• Wayin Hub deployment & application architecture

• How we scale, deploy and do backups

• About Cloud Formation Templates

• About vendor lock-in

•Designing for orchestration

Friday, June 21, 13

Page 39: Wayin devops-2013

Choose right components

• Good

• Peer-to-peer

• Linear scalability

• Bad

• Master-slave

• “Special” servers

• Single point-of-failure

Friday, June 21, 13

Page 40: Wayin devops-2013

Bootstrap everything

• Every instance must self-configure

• Make services easy to discover

Friday, June 21, 13

Page 41: Wayin devops-2013

Keep it simple

• Minimize number of different...

• Server types

• External services

• Learning curves

Friday, June 21, 13

Page 42: Wayin devops-2013

Questions?

Friday, June 21, 13