GKE 上的 HPA 规模部署为 0

HPA scale deployment to 0 on GKE

我正在尝试将 HPA 与外部指标结合使用以将部署缩减为 0。我正在使用版本为 1.16.9-gke.2 的 GKE。

根据 this 的说法,我认为它会起作用,但事实并非如此。我仍然面临:The HorizontalPodAutoscaler "classifier" is invalid: spec.minReplicas: Invalid value: 0: must be greater than or equal to 1

以下是我的 HPA 定义:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: classifier
spec:
  minReplicas: 0
  maxReplicas: 15
  metrics:
  - external:
      metricName: loadbalancing.googleapis.com|https|request_count
      targetAverageValue: "1"
    type: External
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: classifier

非常感谢您的帮助!

According to this I thought it would be working but it's not.

某些功能在 Kubernetes 中运行的事实并不意味着它们在 GKE.

等托管解决方案中启用

此功能由名为 HPAScaleToZero功能门 启用。自 Kubernetes 版本 1.16 以来,它处于 Alpha 状态。根据下面 link 默认情况下它是禁用的。 请在此处查看有关功能门的官方文档:Kubernetes.io: Docs: Feature Gates

更进一步:

New features in Kubernetes are listed as Alpha, Beta, or Stable, depending upon their status in development. In most cases, Kubernetes features that are listed as Beta or Stable are included with GKE

Cloud.google.com: Kubernetes Engine: Kubernetes versions and features

如您所见:

The HorizontalPodAutoscaler "classifier" is invalid: spec.minReplicas: Invalid value: 0: must be greater than or equal to 1

此功能在“标准”GKE 集群中被禁用。


有一个选项可以启用 HPAScaleToZero。这需要 运行 一个 alpha 集群:

The term alpha cluster means that alpha APIs are enabled, both for Kubernetes and GKE, regardless of the version of Kubernetes the cluster runs. Periodically, Google offers customers the ability to test GKE versions that are not generally available, for testing and validation.

Cloud.google.com: Kubernetes Engine: Alpha clusters

请记住 运行 alpha 集群有一些缺点:

Limitations

Alpha clusters have the following limitations:

  • Not covered by the GKE SLA
  • Cannot be upgraded
  • Node auto-upgrade and auto-repair are disabled on alpha clusters
  • Automatically deleted after 30 days
  • Do not receive security updates