2

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

2 Answers2

1

if you are on GKE and facing issue where enabled API are

autoscaling/v1
autoscaling/v2beta1

while GKE version is around 1.12 to 1.14 you wont be able to apply manifest of autoscaling/v2beta2 however you can apply same thing something like

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: core-deployment
  namespace: default
spec:
  maxReplicas: 9
  minReplicas: 5
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: core-deployment
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageValue: 500m

if you want based on utilization

    apiVersion: autoscaling/v2beta1
    kind: HorizontalPodAutoscaler
    metadata:
      name: core-deployment
      namespace: default
    spec:
      maxReplicas: 9
      minReplicas: 5
      scaleTargetRef:
        apiVersion: extensions/v1beta1
        kind: Deployment
        name: core-deployment
      metrics:
      - type: Resource
        resource:
          name: cpu
          targetAverageUtilization: 80
Harsh Manvar
  • 126
  • 2
1

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
metadata:
  name: php-apache
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        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
metadata:
  name: myapp-hpa
  namespace: myapp
spec:
  minReplicas: 3
  maxReplicas: 15
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: myapp
  metrics:
    - type: Resource
      resource:
        name: memory
        targetAverageUtilization: 60
    - type: External
      external:
        metricName: loadbalancing.googleapis.com|https|request_count
        metricSelector:
          matchLabels:
            resource.labels.url_map_name: k8s-um-myapp-myapp-ingress--64658eaf6b9dce0
        targetAverageValue: 100

I scale based on the RAM and on the requests.

HTH

linuxbandit
  • 111
  • 2
  • 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 08 '19 at 16:35