【问题标题】:GKE HPA metricSelector: possible to filter by namespace?GKE HPA metricSelector:可以按命名空间过滤吗?
【发布时间】:2021-06-28 11:14:03
【问题描述】:

我最近在同一个 GKE 集群的不同命名空间中部署了我的应用的测试版本。我的应用程序使用 GPU 资源,我的 HPA 应该根据 GPU 负载自动扩展。

我注意到,尽管负载为零,但 HPA 正在扩展到最大数量的副本。

原因似乎是kubernetes.io|container|accelerator|duty_cycle 指标并非特定于命名空间。我的matchLabels 过滤器针对api 部署,它存在于两个命名空间(defaultstaging)中。

如何另外按命名空间过滤?我试过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

【问题讨论】:

  • 您可以随时向您的部署添加一个额外的标签,例如“metadata.namespace=$namespace”,然后应用您的过滤器。我不确定 HPA 资源是否能够直接过滤命名空间。
  • 谢谢。 $namespace 是占位符还是会自动被命名空间替换?
  • 这只是注释中的一个占位符,所以你知道需要用实际的命名空间替换它
  • @meaningqo 如果您确定 namespace 不是 HPA 可以过滤的资源,请随时给出答案。我会接受的!
  • 谢谢@otherguy 添加了答案并链接到文档以供将来参考

标签: kubernetes google-kubernetes-engine hpa


【解决方案1】:

Resourcetype Horizo​​ntalPodAutoscaler 无法直接过滤命名空间。 但是,您始终可以将命名空间作为标签添加到要过滤的资源中。

更多关于metrics-filter的信息可以在the official api documentation找到,它将metricSelector指定为一个labelSelector

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 2016-03-02
    • 2012-06-24
    • 2019-02-19
    • 1970-01-01
    相关资源
    最近更新 更多