Search This Blog

Saturday, December 10, 2016

Part - 10 - AWS - Autoscaling

Autoscaling

o   Based on custom policies, schedules, or metric monitoring
§  Can use any metric CloudWatch measures
o   Scaling out ensures performance to handle demand
§  Adding instances
o   Scaling in minimizes cost when resources are no longer needed
§  Removing instances
Ø  Auto Scaling is enabled by Amazon CloudWatch
o   No additional fees other than CloudWatch fees
o   All instances launched using Auto Scaling will have detailed monitoring automatically enabled
Ø  Can configure Auto Scaling with web console, command-line tools, or APIs
o   This section will focus on the command-line tools
o   You can explore the web console in the exercise bonus

Why Use Auto Scaling?

Ø  Ensure that a minimum number of instances is always running
o   Auto Scaling will make sure that number of instances is always running
o   If an instance terminates for any reason, a new one will be started
o   Can also be used to keep instance count at a fixed size
§  Delete “extra” instances started by mistake
Ø  Automatically scale instances to meet demand
o   Can specify quantity of instances to launch or terminate as demand requires
§  For example, add or remove five instances at a time
o   Can specify a “cool-down” period to wait before taking action

Two Steps to Get Started With Auto Scaling

Ø  Create a launch configuration, specifying
o   A name for the launch configuration
o   The image (AMI) to use when creating instances
o   The instance type

# aws autoscaling create-launch-configuration --launch-configuration-name user01LC--image-id ami-1235564a --instance-type m1.small –-key-name Crs1205EC2Key--security-groups sg-7a91c610

Ø  Create an Auto Scaling group, specifying
o   A name for the group
o   The launch configuration to use
o   One or more subnets (separated by commas) to run the instances in
o   Minimum instance count
o   Maximum instance count

# aws autoscaling create-auto-scaling-group --auto-scaling-group-name user01ASGrp --launch-configuration-name user01LC --vpc-zone-identifier subnet-41767929c --min-size 2 --max-size 4

Ø  After creating an Auto Scaling group
o   The minimum number of instances will automatically be started
o   No other action is needed for this to happen
Ø  The Auto Scaling group ensures that the minimum number of instances are always running
o   New instances will automatically be started if necessary

Checks, Policies, and Actions

Ø  Health check
o   A check of the health of an instance within an Auto Scaling group
o   Uses standard EC2 health checks by default
o   Can also use custom Elastic Load Balancing (ELB) health checks
§  Will be seen shortly
o   If an instance is marked not healthy, it is immediately scheduled for replacement
§  By default, it is not allowed a chance to recover
Ø  Policy
o   Instructions on how to change the instance count size
o   Can specify the size as an absolute size, increment, decrement, or percentage of current size
Ø  Triggers
o   Combination of an Auto Scaling policy and CloudWatch alarm

Three Types of Scaling

Ø  Manual scaling
o   Change the Auto Scaling group instance counts

# aws autoscaling update-auto-scaling-group --auto-scaling-group-name user01ASGrp --min-size 4 --max-size 10

Ø  Scaling on a schedule
o   Useful when you have a predictable schedule of required demand
o   For example: Run additional servers between 10:00 a.m. and 4:00 p.m.
Ø  Scaling based on triggers and policies
o   Utilize CloudWatch alarm to execute a policy
o   Must define separate policies to scale up and scale down; e.g.:
§  Scale up when bandwidth exceeds a threshold
§  Scale down when average bandwidth falls back down
o   This is the truly “automatic” part of Auto Scaling

Creating a Policy

Ø  Create a new policy

#aws autoscaling put-scaling-policy –-policy-name <PolicyName> --adjustment-type <type> --auto-scaling-group-name <as-group> --scaling-adjustment <adjustment>

o   Type can be ExactCapacity, ChangeInCapacity, PercentChangeInCapacity
Ø  Examples:
o   Scale up by two instances

# aws autoscaling put-scaling-policy –-policy-name IncrBy2Pol --adjustment-type ChangeInCapacity --auto-scaling-group-name user01ASGrp --scaling-adjustment 2

o   Scale down by two instances

# aws autoscaling put-scaling-policy –-policy-name DecrBy2Pol --adjustment-type ChangeInCapacity --auto-scaling-group-name user01ASGrp --scaling-adjustment -2

o   Scale up by 50 percent

--adjustment-type PercentChangeInCapacity –-scaling-adjustment 50

Testing a Policy

Ø  Policies can be tested by executing them manually
o   Good idea to test before utilizing it from a trigger

# aws autoscaling execute-policy --auto-scaling-group-name user01ASGrp --policy-name team02IncrBy2Pol

Ø  Note: An Auto Scaling group always ensures that the running instance count adheres to the minimum and maximum sizes specified in the group
o   Executing a policy will not be allowed to violate this
o   For example, if a maximum size is eight, there will never be more than eight instances
§  Even if the policy says to add 10 instances

Creating a Trigger



Cool-Down Period

The Auto Scaling cooldown period is a configurable setting for your Auto Scaling group that helps to ensure that Auto Scaling doesn't launch or terminate additional instances before the previous scaling activity takes effect. After the Auto Scaling group dynamically scales using a simple scaling policy, Auto Scaling waits for the cooldown period to complete before resuming scaling activities. When you manually scale your Auto Scaling group, the default is not to wait for the cooldown period, but you can override the default and honor the cooldown period. Note that if an instance becomes unhealthy, Auto Scaling does not wait for the cooldown period to complete before replacing the unhealthy instance




Ø  A time period to suspended Auto Scaling
o   Goal is to prevent Auto Scaling from reacting too quickly
§  For example, before a previous scaling activity has finished
Ø  Can specify a cool-down period for an Auto Scaling group
o   Provide the following option to the create-auto-scaling-group command when creating the group:

--default-cooldown <seconds>
--default-cooldown <300s>

Ø  Can also specify a cool-down period for each policy
o   Overrides the group’s cool-down period for that policy
o   Provide the following option to the put-scaling-policy when creating a policy:

--default-cooldown <seconds>

Managing Auto Scaling Resources

Ø  All launch configurations defined can be displayed:

aws autoscaling describe-launch-configurations

Ø  All Auto Scaling groups defined can be displayed:

aws autoscaling describe-auto-scaling-groups

Ø  All policies defined can be displayed:

aws autoscaling describe-policies

Benefits of Auto Scaling

Adding Auto Scaling to your application architecture is one way to maximize the benefits of the AWS cloud. When you use Auto Scaling, your applications gain the following benefits:
·        Better fault tolerance. Auto Scaling can detect when an instance is unhealthy, terminate it, and launch an instance to replace it. You can also configure Auto Scaling to use multiple Availability Zones. If one Availability Zone becomes unavailable, Auto Scaling can launch instances in another one to compensate.
·        Better availability. Auto Scaling can help you ensure that your application always has the right amount of capacity to handle the current traffic demands.

·        Better cost management. Auto Scaling can dynamically increase and decrease capacity as needed. Because you pay for the EC2 instances you use, you save money by launching instances when they are actually needed and terminating them when they aren't needed.

1 comment:

  1. Great post I must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. 4 ps of marketing

    ReplyDelete