- AWS Managed load balancer
- Integrates with many AWS services
- Health check feature
- Types of load balancers - Classic load balancer (deprecated), Application Load balancer, Network Load balancer, Gateway Load balancer
- Security with Security Groups
- SSL/TLS Termination for offloading application with certificate management
Application Load Balancer
- Works are layer 7 (http)
- Load balancing to multiple services called target groups
- Load balancing to multiple applications in a same machine (container)
- Support for http/2 and websocket
- Support for redirects, https to http
- Routing Table to multiple target groups
- based on path in url
- based on hostname in url
- based on query string in url
- ALB is great fit for micro-services and container-based application
- Has a port mapping feature to redirect to dynamic port of ECS
- Has a fixed hostname
- Target group gets the client ip in header in x-forwarded-for, x-forwarded-proto
What can be target groups in ALB
- EC2 instances, can be managed by ASG
- ECS tasks
- Lambda functions
- IP Addresses, must be private address
Hands-On
- ELB is listed under feature of EC2
- Select type of load balancer - ALB
- Load balancer Name
- Scheme - Cannot be changed after creation - Internet-facing or Internal (Require private IPs)
- IP address Type - IPV4
- Mappings - Atleast two AZ, for obvious reason, as traffic will be directed to the respective AZ
- Security Group - Add firewall rules
- Listeners and routing - Based on listener rules, traffic is routed to the target group added to the listener
- Create Target Groups - Give tg name, protocol, health check, then register the targets with a port.
- Select the created target group
- Create Load balancer
- Can add rules in listeners, like header, protocol, query string, etc and percentage of traffic routed to the tg group
Network Load Balancer
- Works at layer 4
- Forward the TCP and UDP traffic
- High performance, handled millions of request per sec, and less latency
-
NLB has one static IP per AZ and supports assigning Elastic IP
- Since operates at layer, can be routed directly on IP address.
Hands-On
- Everything is same as ALB, except listener protocol will be TCP, UDP, etc
- Also, option to select Elastic IP address, and in case of Internal, can specify private IP address within the CIDR
Gateway Load Balancers
- This works in layer 3, which is at the Network layer. Somewhat where the home router works at, the home router have IP address, when a traffic comes in, router decides to forward it to which computer connected.
- For Example, gateway load balancer is like a cop, who stops a car (data packet) and directs it to the checkpoint, and to be noted, it is the cop who directs and not checkpoint.
- Now the checkpoint can be like a 3rd party network appliance running on a EC2 instance.
- When it passes through the EC2, the data packet comes back to the GLB and then directed to the application.
SSL Certificates
- Load balancers can listen to HTTPs traffic uses SSL/TLS which can be uploaded to ACM
- ALB and NLB can supports SNI, which is newer protocol to support multiple certificates
Connection Draining
- If a target is set for draining or de-registering in ALB, new connections are stopped, and existing connections given time to finish the process
ASG - Auto Scaling Group
- Helps us to manage variable loads on the application, as EC2 servers can be quickly scaled.
- Ensures the min, max, and desired counts, healthy-unhealthy servers, auto registering and de-registering in Load balancers.
- No cost for ASG, only the underlying EC2 instances and resources will cost
ASG Launch Template
- Its template for the EC2, plus the scaling configs, and scaling policies
- EC2 Attributes
- AMI + Instance Type
- EC2 user data
- EBS Volumes
- Security Groups
- SSH Key pair
- IAM Roles for EC2 instance
- Network + Subnets information
- Load Balancer Information
ASG Hands On
-
Go to ASG in EC2 Page
-
Create ASG
-
Step 1 :
- Give ASG Name
- Select or Create Launch Template
- Create Launch Template, Give Template Name
- Select AMI, instance type, ssh key pair, subnets, volume, user data, etc (basically its same EC2 form)
-
Step 2: Instance Launch Option