ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Traffic တက်လာရင် pod count ကို တိုးချင်ပါတယ် — `kubectl scale deployment web-deployment --replicas=10` နဲ့ manual scale လုပ်လို့ရပေမယ့်, midnight မှာ traffic ကျသွားရင် ပြန်လျှော့ဖို့ ဘယ်သူမှ မလုပ်ရင် resource ဖြုန်းနေမှာပါ။ HPA (Horizontal Pod Autoscaler) က CPU/memory usage (ဒါမှမဟုတ် custom metric) ကို monitor လုပ်ပြီး, target threshold ကျော်ရင် pod ကို auto-scale up, threshold အောက်ကျရင် auto-scale down လုပ်ပေးပါတယ် — 'scale ကို ကိုယ်တိုင်စောင့်ကြည့်စရာ မလိုတော့ပါ'.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
HPA ကို `kubectl autoscale deployment web-deployment --min=2 --max=10 --cpu-percent=70` ဆိုတာမျိုးနဲ့ create လုပ်ရင် — average CPU usage 70% ကျော်ရင် pod count ကို max 10 အထိ တိုးပေးပြီး, load ကျသွားရင် min 2 အထိ ပြန်လျှော့ပေးပါတယ်။ HPA ကို run ဖို့ metrics-server ဆိုတဲ့ add-on ကို cluster မှာ install ထားရပါမယ် (CPU/memory data ကို ပေးတဲ့ component ပါ).
အတူတူ ကြည့်မယ်
# Manual scale
kubectl scale deployment web-deployment --replicas=10
# Create an HPA: 2-10 pods, target 70% CPU
kubectl autoscale deployment web-deployment \
--min=2 --max=10 --cpu-percent=70
# Watch HPA in action
kubectl get hpa web-deployment --watchNAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS
web-deployment Deployment/web-deployment 45%/70% 2 10 3၅ မိနစ် စမ်းကြည့်
HPA တစ်ခု create လုပ်ကြည့်ပြီး `kubectl get hpa --watch` နဲ့ target/replicas ကို ကြည့်ကြည့်ပါ (traffic မရှိရင် minimum replica ပဲ ရှိနေမှာပါ, ဒါက ပုံမှန်ပါ)။
သတိလေးတစ်ချက်
HPA က CPU/memory 'requests' value ပေါ်မူတည်ပြီး percentage တွက်ပါတယ် — Pod spec ထဲမှာ resource requests ကို မသတ်မှတ်ထားရင် HPA က properly အလုပ်မလုပ်နိုင်ပါ။