Ec2 part2
Class 10th Elastic compute cloud Apr 23rd
- Load Balancer
- Target groups
- Launch Templates
- Auto scaling
Step1: VPC Created
Created One VPC with CIDR block 10.0.0.0/22 that means 32-22=10 ,Power(2,10)=1024 Subnet Ips we can able create
Step2:We have created 6 subnets 3 for public and 3 for private for above VPC, with different available zones.
Step4:Click all your public and private subnet edit subnet check enable auto-assign public and save
Step6:
What is the ELB?
Elastic load balancing automatically distributes incoming application traffic access multiple targets,such as amazon instances,container, IP addresses,lambda functions and virtual appliances.
https://google.com search(user)-->Webserver-->database
Web server has capacity limited(if request came more than capacity system will crash,so the reason implemented load balancer
user -->loadbalacer->Webserver -->Webserver -->database
the load balancer equal to distributed multiple webserver instances
Elastic Load balancing types
1.Application load balancer (commonly used ,round robin method distribute)
2.Network load balancer
3.Gateway load balancer
4.Classic load balancer (old one)
Target groups :we have registered instance to the target group which is you have created
Target groups route requests to one or more registered targets, such as ec2 instances, using the protocol and port number that you specify.
You can register a target with multiple target groups. You can configure health checks on a per targetgroup basis.
Health checks are performed on all registered to a target group that is specified in a listener rule for your load balancer
Practical
Step7: Need to attach internet gateway to private /public Route table also.
Step8:We have to three instance created,
Step9: Advance details and scrip user data Apache data and click launch
#!/bin/bash -xe
# STEP1 -Updates
yum -y update
# STEP2 -Begin Configuration
yum -y install httpd
systemctl enable httpd
systemctl start httpd
# STEP3 -Customer Web Page
echo "<h1> Welcome to Website1</h1>" >> /var/www/html/index.html
Step10: Three instances created with three different zone due high availability
VM_Inst_website1,VM_Inst_website2,VM_Inst_website3 and modify iam security attach admin for all 3 VM's
Our three instance check all click include as pending as below
and click create target group
After registered Target group inital it will consequently health check ,while health 200 success code need get response, if not our instance is not healthy
Every 30 seconds target do the health for the instance if any issue on instance that server went to
unhealth state
Create Load balancer Application Load Balancer
Step1:
Click load balancer
as you see below same website url connected ,different sites, this way load balancer will work
Step3: Just for test stop the one instance and then need to target group available zone
Step4:As you see below one avaaille zone went unsed state
Autoscaling
(whenevery one instance was down, autscaling automatically create on instance and attach to target gropd)
Autoscaling is monitoring your applications automatically adjust the capacity to maintain steady, predicatable performance at the lowest possible cost.
Using AWS auto scaling, it's easy to setup application scaling for multiple resources across multiple service in minutes
It's easy to get stared with auto scaling using the AWS management console,command line interface (CLI), or SDK
AWS Auto scaling is available at no additional charge .You pay only of the AWS resources needed to run your applications and amazon cloud watch monitoring fees.
Type of Scaling
- Vertical Scaling
- Horizontal Scaling
Vertical scaling means increasing the capacity of the existing resource .Increasing RAM capacity, adding additional volumes, change the instance family under this category
Note: Vertical scaling need change capacity for instance need downtime/stop instance
Horizontal
(For Particular time you want required instance capacity need to increase with out downtime ,we implement Horizontal downtime)
Horizontal scaling means adding additional nodes or machines to your infrastructure as per demand.
we can setup automation to this scaling.
Launch Template
Create Template choose the instance type t2.micro free tier
Additional details,pls User data give below information
#!/bin/bash -xe
# STEP1 -Updates
yum -y update
# STEP2 -Begin Configuration
yum -y install httpd
systemctl enable httpd
systemctl start httpd
# STEP3 -Customer Web Page
echo "<h1> Welcome to Blog</h1>" >> /var/www/html/index.html
Not to change anything click Create lunch template
autoscaling create the instance based which specified on the launch template
Click Next
Choose your VPC and select all private subnet click next
Enter how many instances you need
Give 3 click next >add notification >click next -->add tag >click next
Step7:
Click create autoscaling group
Once create Autoscaling group ,Three instance automatically created As you above it was created three availability zones, we have specified launch template
and autoscaling show three availability zones
As you see using public IP , all http pages are opened All Instance we have put private, we have put only loadbalacer public
As see Target groups are health state.
Test Auto scaling now, terminate one instance manually , need check is will automatically create instance or not using autoscaling
Terminate one instance
Terminated done
You see automatically one more instance created by autoscaling ,After 300 seconds
You see our webpage all also automatically came ,autoscaling created instance with same configuration and out webpage
Below out autoscaling min once created max 3 instance automatically
Autoscaling ,We can Instance CPU utalinzation also based on target value 50 % more, it will create
new instance automatically and distributed the load balance
Terminate the instance
delete autoscaling
delete loadbalance
delete targetgroups
--Thanks