當電商網站舉辦周年慶活動時,網站的瀏覽流量一定會面臨到網站掛掉或網站速度很慢,當然解決辦法也有相對應的解決辦法:
Ps. HPA也有支援cooldown的功能,避免增加/減少太多Pod,緩衝區的概念
講解如何建立HPA在EKS上,如下步驟:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-
server/releases/latest/download/components.yaml
kubectl apply -f hpa.yaml
kubectl autoscale deployment hpa-deploy --cpu-percent=50 --min=1 –
max=10
kubectl describe hpa/hpa-deploy
kubectl get hpa/hpa-deploy
hpa.yaml是由Service和Deployment,設定都跟之前的文章一樣
apiVersion: v1
kind: Service
metadata:
name: hpa-svc
labels:
app: hpa-svc
spec:
type: NodePort
selector:
app: hpa-deploy
ports:
- port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hpa-deploy
labels:
app: hpa-deploy
spec:
replicas: 1
selector:
matchLabels:
app: hpa-deploy
template:
metadata:
labels:
app: hpa-deploy
spec:
containers:
- name: hpa-deploy
image: johnson860312/awswebdb
ports:
- containerPort: 80
resources:
limits:
memory: "512Mi"
cpu: "256m"
requests:
memory: "256Mi"
cpu: "128m"
這邊也是使用ApacheBench(ab)進行測試,雖然筆者有設定NodePort把Pod做expose,但需要在EC2上設定SG,增加NodePort為inbound rule,這邊直接使用kubectl port-forward的方式,來訪問到Pod
HPA大致就講解到這裡,明天開始會講EKS的Storage系列