我最近在同一GKE集群的不同命名空间中部署了我的应用程序的测试版本。我的应用程序利用GPU资源,我的HPA应该根据GPU负载自动缩放。
我注意到HPA正在扩展到最大数量的副本,尽管没有负载。
原因似乎是kubernetes.io|container|accelerator|duty_cycle
度量不是特定于命名空间的。我的matchLabels
过滤器针对的是api
部署,它存在于两个名称空间(default
和staging
(中。
如何额外按命名空间进行筛选?我试过metadata.namespace
,但不起作用。
这是HPA:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: api-hpa
namespace: staging
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 1
maxReplicas: 3
metrics:
- type: External
external:
metricName: kubernetes.io|container|accelerator|duty_cycle
metricSelector:
matchLabels:
metadata.system_labels.top_level_controller_name: api
metadata.system_labels.top_level_controller_type: Deployment
targetAverageValue: "75"a
$ kubectl describe hpa api-hpa
Name: api-hpa
Namespace: staging
Labels: <none>
Annotations: <none>
CreationTimestamp: Sun, 27 Jun 2021 23:53:33 +0200
Reference: Deployment/api
Metrics: ( current / target )
"kubernetes.io|container|accelerator|duty_cycle" (target average value): 65 / 75
Min replicas: 1
Max replicas: 3
Deployment pods: 3 current / 3 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from external metric kubernetes.io|container|accelerator|duty_cycle(&LabelSelector{MatchLabels:map[string]string{metadata.system_labels.top_level_controller_name:api,metadata.system_labels.top_level_controller_type: Deployment,},MatchExpressions:[]LabelSelectorRequirement{},})
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Resourcetype HorizontalPodAutoscaler无法直接过滤命名空间。但是,您总是可以将命名空间作为标签添加到要筛选的资源中。
有关度量过滤器的更多信息可以在官方api文档中找到,该文档将metricSelector指定为标签Selector