指标¶
指标配置定义了自动扩缩器监视的指标类型。
按修订版本设置指标¶
对于按修订版本配置,这通过使用 autoscaling.knative.dev/metric 注解来确定。可以按修订版本配置的可能指标类型取决于您使用的自动扩缩器实现类型
- 默认的 KPA 自动扩缩器支持
concurrency和rps指标。 - 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> 是您的自定义指标。