Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the possible metrics for kubernetes autoscaling defined

I'm trying to play with autoscaling scenarios (currently with microk8s single node personal cluster).

Basic CPU scaling works fine.

For the more complex scenarios, I'm trying to follow the guide at https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics but I can't figure out how / where the possible pod metrics / object metrics are defined / documented. For example, .. where is "packets-per-second" documented .

I can kind of navigate via kubectl or manually exercising the REST APIs but there has to be a better way.

Thanks

apiVersion: autoscaling/v2beta1
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: AverageUtilization
        averageUtilization: 50
  - type: Pods
    pods:
      metric:
        name: packets-per-second ====> where is this name defined/documented ?
      targetAverageValue: 1k
  - type: Object
    object:
      metric:
        name: requests-per-second ====> where is this name defined/documented ?
      describedObject:
        apiVersion: networking.k8s.io/v1beta1
        kind: Ingress
        name: main-route
      target:
        kind: Value
        value: 10k
like image 803
Vinay B Avatar asked Aug 02 '19 16:08

Vinay B


People also ask

How do you check auto scaling in Kubernetes?

We can check the status of autoscaler by running the $kubclt get hpa command. We will increase the load on the pods using the following command. We can check the hpa by running $ kubectl get hpa command. We can check the number of pods running using the following command.

Can we auto scale Kubernetes pods based on custom metrics?

The Horizontal Pod Autoscaler is a built-in Kubernetes feature that allows to horizontally scale applications based on one or more monitored metrics. Horizontal scaling means increasing and decreasing the number of replicas. Vertical scaling means increasing and decreasing the compute resources of a single replica.

How does Kubernetes auto scale?

In Kubernetes, a HorizontalPodAutoscaler automatically updates a workload resource (such as a Deployment or StatefulSet), with the aim of automatically scaling the workload to match demand. Horizontal scaling means that the response to increased load is to deploy more Pods.


2 Answers

CPU or Memory usage in ResourceMetric is provided by kubelet and collected by metric-server

But for packets-per-second and requests-per-second, there are no official provider, so this field can actually be any value, depend on the non-official custom metrics API you deployed.

Some popular custom metrics API are listed at https://github.com/kubernetes/metrics/blob/master/IMPLEMENTATIONS.md

like image 184
menya Avatar answered Nov 16 '22 00:11

menya


The GitHub project below provides a lot of information about using custom metrics provided by Prometheus for autoscaling of Pods in Kubernetes.

https://github.com/stefanprodan/k8s-prom-hpa

like image 31
Iman Avatar answered Nov 16 '22 00:11

Iman