在 AWS EKS 中,HPA (horizo​​ntal-pod-autoscaler) 无法获得 cpu 利用率

作为初创公司的后端开发人员,为了第一次申请 Kubernetis,我查找了 AWS 的 EKS 指南,找到了一个很好的文档并遵循了它。

该指南的链接如下。 https://aws-eks-web-application.workshop.aws/en/10-intro.html

在这里,我从 2-1 的 AWS Account 方法开始,我省略了之前的所有选项。

前任。 5-2。 (选项)添加控制台凭据

在最初的尝试中,我们继续使用 Option 进行流程,因为我们在进度申请阶段继续失败并且正在尝试新事物。

在“10-1. Apply HPA stage”之前,所有过程都很容易。

但是,当我通过 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

为了解决这个问题,我们找了很多方法,但是因为我们对Kubernetes的了解还很少,所以没有找到合适的解决方案。

目前创建的yaml设置文件如下。

Bashshell 中使用的所有指令都遵循指南,除了已弃用的错误之外没有任何严重错误。

我该如何解决这个错误?


烧瓶-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

烧瓶部署.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
stack overflow In AWS EKS, HPA (horizontal-pod-autoscaler) failed to get cpu utilization
原文答案
author avatar

接受的答案

HPA works on the Metrics server data to scale POD or not.

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

installation : https://docs.aws.amazon.com/eks/latest/userguide/metrics-server.html

In AWS you have to install it first, which in GKE it's come already installed by default.

https://aws.amazon.com/premiumsupport/knowledge-center/eks-metrics-server/

You can check if metrics server running or not using

kubectl top pods

if output comes with resource usage your metrics server is up & running, there is some another issue with HPA.


答案:

作者头像

You need to install metrics-server to get cpu and memory metrics.