Top Banner
Building an Autoscaler for DigitalOcean Jordan Stone Notion
18

Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Aug 12, 2015

Download

Software

Jordan Stone
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: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Building an Autoscaler for DigitalOcean

Jordan Stone Notion

Page 2: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

What We’ll Talk About and In What Order

• What is Notion?

• Why DigitalOcean is awesome

• Why DigitalOcean is less awesome than other cloud hosting solutions

• Introducing autoscaler

• Deep dive into autoscaler

• Q & A

@notion

Page 3: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Sound

Temperature

Light

OrientationNatural Frequency

Proximity

Acceleration

Water

@notion

Page 4: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Why DigitalOcean is Awesome

• Cheap

• Fast

• Growing (quickly)

• Pre-built images

• Techstars company

@notion

$5 (< 1 cent/hour) for their cheapest dropletThird largest cloud host in the world

Page 5: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Why DigitalOcean is less awesome than other cloud hosting solutions

Feature DigitalOcean AWS Rackspace

File Storage

CDN

Autoscaling

Load Balancing

Security/Access Control

@notion

Page 6: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Autoscaler’s Architecture• Consists of two parts

• One runs on the same server as HAProxy

• The other runs on a “primary” app server

• Uses RabbitMQ as a messaging queue

• Uses the DigitalOcean API and a standard server naming scheme to add/remove servers from HAProxy

@notion

Page 7: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

In order to automatically scale, we need to…

• Define which application to scale

• Define a threshold that triggers scaling out

• Define a threshold that triggers scaling in

• Define how long the threshold should be passed before we scale

• Define a minimum and maximum number of servers

• Add/remove a server to our load balancer

@notion

Page 8: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Defining which application to scale

• How do others do it?

• Launch Configurations and Autoscaling Groups

• Is there a DigitalOcean equivalent?

• Sort of yes, sort of no

@notion

Page 9: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Launch Configuration

Autoscaling Group

Scaling Policies

@notion

Page 10: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Mimicking a Launch Configuration

• DigitalOcean server snapshots

• User configuration

• Common packages (fail2ban, linus, etc.)

• Not the easiest to find

• Difficult to maintain

@notion

Page 11: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Mimicking an Autoscale Group

• DigitalOcean has no concept of grouping or tagging servers

• We can use a common server naming scheme to group servers

• server_prefix: Which application to deploy

• region: Where to deploy it

• environment, domain: more precise groupings

@notion

Page 12: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Mimicking Scaling Policies

• Minimum/Maximum number of servers

• Define an arbitrary amount of scaling criteria

• Currently, just CPU utilization

• Define what to do after a new server is provisioned

• User data

@notion

We use user data script to pull a docker image from a private repository and run the container

Page 13: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Notifications via Messaging Queue

• We use RabbitMQ, but easy to swap

• Servers report metrics via topics

• cpu, response_time, etc.

• Routing key is server hostname

• Helps determine which scaling group to check

@notion

Page 14: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Monitoring Servers

• Add CPU utilization reporter to primary server

• Run as cron job

• CpuMonitor sends CPU utilization to load balancer

• Publishes to ‘cpu’ topic that load balancer subscribes to

@notion

This program runs on the primary server and just creates a CPU topic and publishes the CPU utilization to the exchange with the server’s hostname as its routing key

Page 15: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Autoscaling• Copy monitor_balancer.rb to server with load

balancer

• Monitor subscribes to topics for various metrics (e.g. CPU utilization)

• Autoscalr determines if cluster should be scaled up or down

• After scaling happens, dynamically reload HAProxy config file using DigitalOcean API

@notion

Page 16: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Start autoscaler• Install required gems, RabbitMQ Server

• See README for instructions

• Configure RabbitMQ server

• See README for instructions

• Copy central/ to HAProxy server

• Copy send_cpu_util.rb to primary server

• Copy autoscaler.yml.example to autoscaler.yml

• Run /path/to/ruby /path/to/monitor_balancer.rb -h digitalocean -l haproxy -h 1.1.1.1 -u user -p password -o vhost

@notion

Page 17: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

To Do

• Further break apart and containerize services

• Support server monitoring API’s

• Support > 1 app server

• Support multiple cloud hosting providers

@notion

Page 18: Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015

Jordan StoneChief Software [email protected]

@cheddz

https://github.com/LoopLabsInc/autoscalr

@notion

Thanks!