【问题标题】:Kubernetes - HPA won't autoscale the podsKubernetes - HPA 不会自动缩放 Pod
【发布时间】:2021-01-26 05:51:17
【问题描述】:

我正在部署我使用 node 构建的微服务应用程序。

问题

当我使用 Jmeter 加载负载时,Pod 不会自动缩放。 CPU 利用率达到 50m,它不会调用 HPA 来开始自动缩放。我希望它在达到 CPU 请求的 80%(即 10m)时立即开始复制。

HPA 配置:

# apiVersion: autoscaling/v1 
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler 
metadata: 
  name: client-hpa 
  namespace: default 
spec: 
  minReplicas: 1
  maxReplicas: 4  
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80
  scaleTargetRef: 
    # apiVersion: apps/v1beta1
    apiVersion: apps/v1
    kind: Deployment 
    name: client-depl

部署配置:

apiVersion: apps/v1
kind: Deployment 
metadata: 
    name: client-depl 
spec: 
    replicas: 1
    selector: 
        matchLabels: 
            app: client 
    template: 
        metadata:
            labels: 
                app: client 
        spec: 
            containers: 
                - name: client 
                  image: <docker-id>/<image-name>
                  resources: 
                    requests: 
                        memory: 350Mi
                        cpu: 10m    ### I want it to autoscale when it reaches 8m ###

另外,kubectl get hpa 显示以下输出:

$ kubectl get hpa
NAME         REFERENCE                TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
client-hpa   Deployment/client-depl   <unknown>/80%   1         4         1          8m32s

【问题讨论】:

  • 你安装了metrics-server吗?

标签: kubernetes microservices google-kubernetes-engine amazon-eks


【解决方案1】:

HPA 基于以下等式

desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]

如您所见,公式基于当前的 CPU 利用率,而不是 CPU 请求。 (我希望它达到 8m 时自动缩放)。

也就是说,您可能对以下内容感兴趣:

Vertical Pod Autoscaling

【讨论】:

  • 那么我指定的百分比将参考型号CPU?我不确定是不是这样,因为我见过使用 80% 的文档。如果它基于 Node 的 CPU,那就没有意义了。你能详细说明吗? 我想要水平缩放 pod
  • 您指定的百分比是部署的所有 Pod 中所需的平均 CPU。没错,这不是 Node CPU。你还需要区分cpu request和current cpu value,它们是不同的。
  • 举个例子,如果当前 cpu 值为 63%,期望值为 80%,当前副本数为 3,我们有 (63/80)*3=2.36,因此期望值为 3。
  • 这里的 80% 是多少? 80% 是什么?
  • 80% 平均 pod cpu 跨部署
猜你喜欢
  • 2020-04-16
  • 1970-01-01
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 2017-05-20
  • 1970-01-01
  • 2020-05-05
  • 1970-01-01
相关资源
最近更新 更多