1. 程式人生 > 其它 >AWS學習筆記(八):LB, ASG, EBS

AWS學習筆記(八):LB, ASG, EBS

Why use a load balancer?

  • Spread load across multiple downstream instances
  • Expose a single point of access (DNS) to your application
  • Seamlessly handle failures of downstream instances
  • Do regular health checks to your instances
  • Provide SSL termination (HTTPS) for your websites
  • Enforce stickiness with cookies
  • High availability across zones
  • Separate public traffic from private traffic

Types of load balancer on AWS

  • AWS has 4 kinds of managed Load Balancers
  • Classic Load Balancer (v1 - old generation) – 2009 – CLB
    • HTTP, HTTPS, TCP, SSL (secure TCP)
    • Supports TCP (Layer 4), HTTP & HTTPS (Layer 7)
    • Health checks are TCP or HTTP based
    • Fixed hostname : xxx.region.elb.amazonaws.com
  • Application Load Balancer (v2 - new generation) – 2016 – ALB
    • HTTP, HTTPS, WebSocket
    • Application load balancers is Layer 7 (HTTP)
    • Load balancing to multiple HTTP applications across machines (target groups)
    • Load balancing to multiple applications on the same machine (ex: containers)
    • Support for HTTP/2 and WebSocket
    • Support redirects (from HTTP to HTTPS for example)
    • Routing tables to different target groups:
      • Routing based on path in URL (example.com/users & example.com/posts)
      • Routing based on hostname in URL (one.example.com & other.example.com)
      • Routing based on Query String, Headers (example.com/users?id=123&order=false)
    • ALB are a great fit for micro services & container-based application (example: Docker & Amazon ECS)
    • Has a port mapping feature to redirect to a dynamic port in ECS
    • In comparison, we'd need multiple Classic Load Balancer per application
    • Target Groups:
      • EC2 instances (can be managed by an Auto Scaling Group) – HTTP
      • ECS tasks (managed by ECS itself) – HTTP
      • Lambda functions – HTTP request is translated into a JSON event
      • IP Addresses – must be private IPs
      • ALB can route to multiple target groups
      • Health checks are at the target group level
    • Fixed hostname (xxx.region.elb.amazonaws.com)
    • The application servers don’t see the IP of the client directly
    • The true IP of the client is inserted in the header X-Forwarded-For 請求標頭可自動新增並幫助您識別客戶端的 IP 地址
    • We can also get Port (X-Forwarded-Port 請求標頭可幫助您識別客戶端與您的負載均衡器連線時所用的目標埠) and proto (X-Forwarded-Proto 請求標頭可幫助您識別客戶端與您的負載均衡器連線時所用的協議 (HTTP 或 HTTPS))
  • Network Load Balancer (v2 - new generation) – 2017 – NLB
    • TCP, TLS (secure TCP), UDP
  • Gateway Load Balancer – 2020 – GWLB
    • Operates at layer 3 (Network layer) – IP Protocol