While following the tutorial found here I saw that I need autoscaling/v2beta2 for having custom metrics for the Horizontal Pod Autoscaler, but don't know how to enable it.

Environment details:

  • Google Cloud platform
  • Kubernetes version 1.13.7-gke.8 (latest)

What did I try:

  • Using "kubectl api-versions", I checked what API groups I have enable for autoscaling and have only the following: autoscaling/v1 autoscaling/v2beta1

  • I found the following documentation that says "Certain resources and API groups are enabled by default. They can be enabled or disabled by setting --runtime-config on apiserver. --runtime-config accepts comma separated values.". Taking a look at the kube-apiserver command documentation , I could find a way to use this command for gcloud


About your API versions: that is fine, with autoscaling/v2beta1 you can even autoscale based on external metrics (e.g. Stackdriver).

About your question: I am not sure what do you mean by "I cannot enable it". From the same page you linked, you can find 80% of the manifest you need:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
  name: php-apache
  namespace: default
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  - type: Resource
      name: cpu
        type: Utilization
        averageUtilization: 50

This manifest says "have between 1 and 10 replicas, based on the CPU utilisation scale more the thing described on scaleTargetRef". You could add also based on memory, and it will work in an "OR" fashion (if one of the two metric will pass the threshold, the scaling will happen). You could finally also add a metric of type: External that would be your Stackdriver source (e.g. number of HTTP requests, number of messages in a queue..). This is generally advised as scaling based on CPU is ineffective.

Once you have the manifest, simply have kubectl apply -f hpa.yaml and you have enabled it.

This is why I am saying I don't get fully your question, do you mean to say you couldn't find a proper manifest? (the one I wrote here is also not 'proper')

I couldn't find the source (it was an article about HPA with external metrics), but here's the manifest for my HPA:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
  name: myapp-hpa
  namespace: myapp
  minReplicas: 3
  maxReplicas: 15
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: myapp
    - type: Resource
        name: memory
        targetAverageUtilization: 60
    - type: External
        metricName: loadbalancing.googleapis.com|https|request_count
            resource.labels.url_map_name: k8s-um-myapp-myapp-ingress--64658eaf6b9dce0
        targetAverageValue: 100

I scale based on the RAM and on the requests.


|improve this answer|||||
  • for custom metrics aswell as support for scaling based on memory, you need autoscaling/v2beta2 .. I'm also wondering how to enable it in GKE – pHiL Nov 8 '19 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.