kubernetes 在AWS EKS中,HPA(水平盒自动定标器)无法获取CPU利用率

ldioqlga  于 2022-11-02  发布在  Kubernetes
关注(0)|答案(2)|浏览(178)

作为一个创业公司的后端开发者,为了第一次应用Kubernetis,我寻找了AWS的EKS指南,找到了一个很好的文档并遵循了它。
该指南的链接如下所示。https://aws-eks-web-application.workshop.aws/en/10-intro.html
在这里,我从2-1中的AWS Account方法开始,并省略了前面的所有选项。
例5-2.(选项)添加控制台凭据
在最初的尝试中,我们继续使用Option,因为我们在进度应用程序阶段不断失败,正在尝试新的东西。
所有的过程都很容易,直到“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

为了解决这个问题,我们从很多方面进行了研究,但是由于我们对Kubernetis的了解还很有限,我们还没有找到一个合适的解决方案。
到目前为止创建的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
4xrmg8kj

4xrmg8kj1#

HPA对Metrics服务器数据进行处理以缩放POD或不缩放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

如果输出伴随着资源使用,您的度量服务器正在启动和运行,则HPA存在其他问题。

mbzjlibv

mbzjlibv2#

您需要install metrics-server来获取cpu和内存指标。

相关问题