跳至内容

指标

指标配置定义了自动缩放器监视的指标类型。

为每个修订设置指标

对于 每个修订 的配置,这将使用 autoscaling.knative.dev/metric 注释确定。可以为每个修订配置的可能的指标类型取决于您正在使用的自动缩放器实现类型。

  • 默认 KPA 自动缩放器支持 concurrencyrps 指标。
  • HPA 自动缩放器支持 cpu 指标。

有关 KPA 和 HPA 的更多信息,请参阅有关 支持的自动缩放器类型 的文档。

  • 每个修订的注释键: autoscaling.knative.dev/metric
  • 可能的值: "concurrency""rps""cpu""memory" 或任何自定义指标名称,具体取决于您的自动缩放器类型。"cpu""memory" 和自定义指标在使用 HPA 类的修订中受支持。
  • 默认值: "concurrency"
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/metric: "concurrency"
        autoscaling.knative.dev/target-utilization-percentage: "70" 

注意

用于“并发”的 autoscaling.knative.dev/target-utilization-percentage 注释指定百分比值。有关更多详细信息,请参阅 配置目标

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/metric: "rps"
        autoscaling.knative.dev/target: "150"

注意

用于“每秒请求数”的 autoscaling.knative.dev/target 注释指定整数。有关更多详细信息,请参阅 配置目标

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
        autoscaling.knative.dev/metric: "cpu"
        autoscaling.knative.dev/target: "100"

注意

用于“CPU”的 autoscaling.knative.dev/target 注释指定毫芯中的整数。有关更多详细信息,请参阅 配置目标

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
        autoscaling.knative.dev/metric: "memory"
        autoscaling.knative.dev/target: "75"

注意

用于“内存”的 autoscaling.knative.dev/target 注释指定 Mi 中的整数。有关更多详细信息,请参阅 配置目标

您可以创建 HPA 以通过您指定的指标缩放修订。HPA 将配置为使用修订的所有 Pod 中您的指标的平均值

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/class: "hpa.autoscaling.knative.dev"
        autoscaling.knative.dev/metric: "<metric-name>"
        autoscaling.knative.dev/target: "<target>"

其中 <metric-name> 是您的自定义指标。

下一步

我们使用分析和 cookie 来了解网站流量。有关您使用我们网站的信息将与 Google 共享,以实现该目的。 了解更多。