Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics to horizontalPodAutoscalerConfig to support custom metrics api #5811

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

imroc
Copy link

@imroc imroc commented May 17, 2024

Add .spec.advanced.horizontalPodAutoscalerConfig.metrics to ScaledObject, so that we can keep some metric specs that uses custom metrics api to auto scale workloads.

For example, a HPA uses custom metrics that provided by cloud vendor's hosted kubernetes cluster (e.g. Tencent TKE's HPA metrics)

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: test
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: test
  minReplicas: 1
  maxReplicas: 100
  metrics:
    - pods:
        metric:
          name: k8s_pod_rate_cpu_core_used_limit
        target:
          averageValue: "80"
          type: AverageValue
      type: Pods
    - pods:
        metric:
          name: k8s_pod_rate_mem_usage_limit
        target:
          averageValue: "80"
          type: AverageValue
      type: Pods
    - pods:
        metric:
          name: k8s_pod_rate_gpu_used_request
        target:
          averageValue: "60"
          type: AverageValue
      type: Pods

With this PR, we can migrate this HPA to KEDA, and add the KEDA trigger to enhance the autoscaling ability:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: test
  namespace: test
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: test
  pollingInterval: 15
  minReplicaCount: 1
  maxReplicaCount: 100
  advanced:
    horizontalPodAutoscalerConfig:
      metrics:
        - pods:
            metric:
              name: k8s_pod_rate_cpu_core_used_limit
            target:
              averageValue: "80"
              type: AverageValue
          type: Pods
        - pods:
            metric:
              name: k8s_pod_rate_mem_usage_limit
            target:
              averageValue: "80"
              type: AverageValue
          type: Pods
        - pods:
            metric:
              name: k8s_pod_rate_gpu_used_request
            target:
              averageValue: "60"
              type: AverageValue
          type: Pods
  triggers:
    - type: cron
      metadata:
        timezone: Asia/Shanghai
        start: 30 9 * * *
        end: 30 10 * * *
        desiredReplicas: "10"

See background: #5810

@imroc imroc requested a review from a team as a code owner May 17, 2024 11:53
imroc added 3 commits May 17, 2024 19:56
Signed-off-by: roc <roc@imroc.cc>
Signed-off-by: roc <roc@imroc.cc>
imroc added 2 commits May 17, 2024 21:44
Signed-off-by: roc <roc@imroc.cc>
Signed-off-by: roc <roc@imroc.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant