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
| Type | Layer | เหมาะกับ |
|---|---|---|
| Application Load Balancer | Layer 7 HTTP/HTTPS | Web app, path/host routing, TLS termination |
| Network Load Balancer | Layer 4 TCP/UDP/TLS | High performance, static IP, non-HTTP protocol |
| Gateway Load Balancer | Layer 3 gateway pattern | Deploy 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
- เลือก ALB, NLB หรือ GWLB ตาม protocol/use case ได้
- อธิบาย listener, rule, target group และ health check ได้
- ตรวจ security group path จาก load balancer ไป target ได้
- ALB เหมาะกับ use case แบบใด?
- Target Group มีหน้าที่อะไร?
- Health Check ที่ผิดพลาดทำให้เกิดอาการอะไร?