บทนำ
บทความนี้อธิบายวิธีการตั้งค่า Horizontal Pod Autoscaler (HPA) บน Sangfor SKE v2.2.0 ซึ่ง HPA จะปรับจำนวน Pod replicas โดยอัตโนมัติตาม metric ที่กำหนด เช่น CPU utilization หรือ memory usage
ข้อกำหนดเบื้องต้น
- Metrics Server ต้องเปิดใช้งานสำหรับ Kubernetes cluster เป้าหมาย
- มี Deployment ที่สร้างไว้แล้วใน Kubernetes cluster โดยต้องกำหนด resource requests ให้กับ Deployment เนื่องจาก resource metrics สำหรับ auto scaling อ้างอิงจาก resource requests
HPA Algorithm
HPA จะปรับจำนวน Pod โดยเปรียบเทียบ current metric value กับ expected metric value ตามสูตร:
Expected Pod Replicas = ceil[Current Pod Replicas * (Current Metric Value / Expected Metric Value)]
ตัวอย่าง:
- ถ้า current metric value เป็น 200m และ expected value เป็น 100m จำนวน Pod จะเพิ่มเป็น 2 เท่า (200.0/100.0 = 2.0)
- ถ้า current metric value เป็น 50m จำนวน Pod จะลดลง 50% (50.0/100.0 = 0.5)
- ถ้า ratio ใกล้ 1.0 (ห่างน้อยกว่า global tolerance 0.1) HPA จะไม่ทำการ scaling
ข้อควรระวัง: หาก Deployment เชื่อมกับ multiple autoscaling policies:
- SCP V1.26 ขึ้นไป: จะเกิด alert "pods by selector xxxx are controlled by multiple HPAs" และ autoscaling policies จะไม่ทำงาน
- SCP versions ก่อน V1.26: autoscaling policy ที่ทำงานจะเป็นแบบ random ทำให้เกิด unexpected frequent Pod scaling
ขั้นตอนที่ 1: การตั้งค่า Autoscaling Policy
1. ไปที่ Resources > Compute > Kubernetes Engine > Namespaces > Load Balancing > Workloads แล้วเข้าหน้า details ของ Deployment ที่ต้องการตั้งค่า autoscaling
2. คลิก Enable ข้าง Autoscaling แล้วเลือก Enable ในหน้าต่าง pop-up
3. กำหนดค่าต่อไปนี้:
- Max Pod Replicas: จำนวน Pod สูงสุดที่อนุญาต
- Min Pod Replicas: จำนวน Pod ต่ำสุดที่อนุญาต
- Trigger Rules: กำหนด metric thresholds สำหรับ trigger auto scaling (รองรับ CPU และ memory metrics)
จากนั้นคลิก OK
ขั้นตอนที่ 2: การแก้ไข Autoscaling Policy
1. ไปที่หน้า details ของ Deployment แล้วคลิก Enable ข้าง Autoscaling
2. แก้ไข autoscaling policy ในหน้าต่าง pop-up ตามต้องการ
ขั้นตอนที่ 3: การปิด Autoscaling
1. ไปที่หน้า details ของ Deployment แล้วคลิก Enable ข้าง Autoscaling
2. ยกเลิกการเลือก Enable ในหน้าต่าง pop-up เพื่อปิด autoscaling
หมายเหตุ
- HPA รองรับ CPU และ memory metrics สำหรับ trigger auto scaling
- ไม่แนะนำให้เชื่อม Deployment กับ multiple autoscaling policies เพื่อหลีกเลี่ยงปัญหา unexpected scaling
- ต้องกำหนด resource requests ให้กับ Deployment ก่อนเปิดใช้งาน HPA เพื่อให้ metrics ทำงานได้ถูกต้อง
บทความที่เกี่ยวข้อง
ข้อคิดเห็น
0 ข้อคิดเห็น
โปรด ลงชื่อเข้าใช้ เพื่อแสดงข้อคิดเห็น