[英]In AWS EKS, HPA (horizontal-pod-autoscaler) failed to get cpu utilization
作為初創公司的后端開發人員,為了第一次應用 Kube.netis,我查找了 AWS 的 EKS 指南,找到了一個很好的文檔並遵循了它。
指南的鏈接如下。 https://aws-eks-web-application.workshop.aws/en/10-intro.html
在這里,我從 2-1 的 AWS 賬戶方法開始,我省略了之前的所有選項。
前任。 5-2。 (可選)添加控制台憑據
在最初的嘗試中,我們以Option進行了流程,因為我們在progress application階段不斷失敗,正在嘗試新事物。
直到“10-1.應用 HPA 階段”之前,所有過程都很簡單。
但是,當我通過 kubectl get hpa 命令檢查 HPA 狀態時,CPU 使用率被標記為未知。
向導說再晚點試試就可以正常出來了,於是我就晚了一個小時試了一下,還是一樣。
因此,當我通過 kubectl describe hpa 命令檢查狀態時,我發現由於缺少 cpu 請求而出現錯誤,如下所示。
Name: demo-flask-backend-hpa
Namespace: default
Labels: <none>
Annotations: <none>
CreationTimestamp: Tue, 14 Sep 2021 09:03:53 +0000
Reference: Deployment/demo-flask-backend
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): <unknown> / 30%
Min replicas: 1
Max replicas: 5
Deployment pods: 1 current / 0 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True SucceededGetScale the HPA controller was able to get the target's current scale
ScalingActive False FailedGetResourceMetric the HPA was unable to compute the replica count: failed to get cpu utilization: missing request for cpu
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedGetResourceMetric 5s horizontal-pod-autoscaler failed to get cpu utilization: missing request for cpu
Warning FailedComputeMetricsReplicas 5s horizontal-pod-autoscaler invalid metrics (1 invalid out of 1), first error is: failed to get cpu utilization: missing request for cpu
為了解決這個問題,我們找了很多方法,但一直沒有找到合適的解決方案,因為我們對Kube.netis的了解還很少。
至此創建的yaml個設置文件如下。
Bashshell 中使用的所有指令都遵循該指南,除棄用錯誤外沒有嚴重錯誤。
我該如何解決這個錯誤?
flask-hpa.yaml
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: demo-flask-backend-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: demo-flask-backend
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 30
flask-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-flask-backend
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: demo-flask-backend
template:
metadata:
labels:
app: demo-flask-backend
spec:
containers:
- name: demo-flask-backend
image: $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/demo-flask-backend:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
resources:
requests:
cpu: 250m
limits:
cpu: 500m
入口.yaml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "backend-ingress"
namespace: default
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- http:
paths:
- path: /contents
pathType: Prefix
backend:
service:
name: "demo-flask-backend"
port:
number: 8080
- path: /services
pathType: Prefix
backend:
service:
name: "demo-nodejs-backend"
port:
number: 8080
- path: /
pathType: Prefix
backend:
service:
name: "demo-frontend"
port:
number: 80
HPA 處理 Metrics 服務器數據以擴展 POD 或不擴展。
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
安裝: https://docs.aws.amazon.com/eks/latest/userguide/metrics-server.html
在 AWS 中,您必須先安裝它,而在 GKE 中,它已經默認安裝。
https://aws.amazon.com/premiumsupport/knowledge-center/eks-metrics-server/
您可以檢查指標服務器是否正在運行或未使用
kubectl top pods
如果 output 與資源使用有關,您的指標服務器已啟動並正在運行,則 HPA 存在另一個問題。
您需要安裝 metrics-server以獲取 cpu 和 memory 指標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.