Lesson 3ELB

Load Balancing

Elastic Load Balancing กระจาย traffic ไปยังหลาย targets เพื่อเพิ่ม availability, health-based routing และรองรับ scaling โดยไม่ให้ผู้ใช้ผูกกับ instance เดียว

Traffic role Load balancer เป็น stable entry point ผู้ใช้เข้าหา ALB/NLB แทนผูกกับ instance ที่อาจถูก replace หรือ scale ได้
Type choice ALB สำหรับ HTTP routing NLB เหมาะ TCP/UDP performance, GWLB เหมาะ appliance/inspection pattern
Health Health check ตัดสิน traffic path Path, status code, SG และ app readiness ต้องตรงกัน ไม่งั้น target จะ unhealthy

Elastic Load Balancing คืออะไร

Elastic Load Balancing หรือ ELB รับ traffic จาก client แล้วกระจายไป targets เช่น EC2 instances, IP addresses, Lambda หรือ containers Load Balancer ตรวจ health ของ targets และส่ง traffic ไปเฉพาะ targets ที่ healthy ตาม configuration

ALB, NLB และ GWLB

TypeLayerเหมาะกับ
Application Load BalancerLayer 7 HTTP/HTTPSWeb app, path/host routing, TLS termination
Network Load BalancerLayer 4 TCP/UDP/TLSHigh performance, static IP, non-HTTP protocol
Gateway Load BalancerLayer 3 gateway patternDeploy network appliances เช่น firewall/inspection

Core components

  • Listener: protocol/port ที่ Load Balancer รับ เช่น HTTPS 443
  • Rule: logic ตัดสินใจ route เช่น host/path condition
  • Target Group: กลุ่ม targets และ health check configuration
  • Health Check: path/protocol/threshold ที่ใช้ตัดสินว่า target healthy หรือ unhealthy

TLS termination

ALB สามารถถือ TLS certificate จาก ACM และ terminate HTTPS ที่ Load Balancer ได้ จากนั้นจะส่งต่อไป target ด้วย HTTP หรือ HTTPS ขึ้นกับ security requirement ของระบบ

Common mistakes

  • Health check path ตอบ 404/500 ทำให้ target unhealthy ทั้งที่ application ทำงานบางส่วน
  • Security Group ของ target ไม่อนุญาต traffic จาก Load Balancer Security Group
  • วาง ALB แค่ subnet/AZ เดียว ทำให้ availability ต่ำ
  • ใช้ NLB กับ HTTP routing requirement ที่ควรใช้ ALB

Review questions

Before next lesson
  1. เลือก ALB, NLB หรือ GWLB ตาม protocol/use case ได้
  2. อธิบาย listener, rule, target group และ health check ได้
  3. ตรวจ security group path จาก load balancer ไป target ได้
  1. ALB เหมาะกับ use case แบบใด?
  2. Target Group มีหน้าที่อะไร?
  3. Health Check ที่ผิดพลาดทำให้เกิดอาการอะไร?