The default supported API is `autoscaling/v2` (available since `v1.23`).
This API MUST be available in the cluster which is the default.
## Building
@@ -73,6 +71,15 @@ export GO111MODULE=on # needed if the project is checked out in your $GOPATH.
$ make
```
## Install in Kubernetes
Clone this repository, and run as below:
```sh
$ cd kube-metrics-adapter/docs
$ kubectl apply -f .
```
## Collectors
Collectors are different implementations for getting metrics requested by an
@@ -84,9 +91,12 @@ HPA resource, or via additional annotations on the HPA resource.
## Pod collector
The pod collector allows collecting metrics from each pod matched by the HPA.
The pod collector allows collecting metrics from each pod matching the label selector defined in the HPA's `scaleTargetRef`.
Currently only `json-path` collection is supported.
### Supported HPA `scaleTargetRef`
The Pod Collector utilizes the `scaleTargetRef` specified in an HPA resource to obtain the label selector from the referenced Kubernetes object. This enables the identification and management of pods associated with that object. Currently, the supported Kubernetes objects for this operation are: `Deployment`, `StatefulSet` and [`Rollout`](https://argoproj.github.io/argo-rollouts/features/specification/).
### Supported metrics
| Metric | Description | Type | K8s Versions |
@@ -99,7 +109,7 @@ This is an example of using the pod collector to collect metrics from a json
metrics endpoint of each pod matched by the HPA.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -219,7 +229,7 @@ with the result of the query.
This allows having multiple prometheus queries associated with a single HPA.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -331,7 +341,7 @@ This is an example of an HPA that will scale based on `requests-per-second` for
an ingress called `myapp`.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -365,7 +375,7 @@ This is an example of an HPA that will scale based on `requests-per-second` for
a routegroup called `myapp`.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -404,6 +414,64 @@ the `backend` label under `matchLabels` for the metric. The ingress annotation
where the backend weights can be obtained can be specified through the flag
`--skipper-backends-annotation`.
## External RPS collector
The External RPS collector, like Skipper collector, is a simple wrapper around the Prometheus collector to
make it easy to define an HPA for scaling based on the RPS measured for a given hostname. When
[skipper](https://github.com/zalando/skipper) is used as the ingress
implementation in your cluster everything should work automatically, in case another reverse proxy is used as ingress, like [Nginx](https://github.com/kubernetes/ingress-nginx) for example, its necessary to configure which prometheus metric should be used through `--external-rps-metric-name <metric-name>` flag. Assuming `skipper-ingress` is being used or the appropriate metric name is passed using the flag mentioned previously this collector provides the correct Prometheus queries out of the
| `requests-per-second` | Scale based on requests per second for a certain hostname. | External | | `>=1.12` |
### Example: External Metric
This is an example of an HPA that will scale based on `requests-per-second` for the RPS measured in the hostnames called: `www.example1.com` and `www.example2.com`; and weighted by 42%.
This metric supports a relation of n:1 between hostnames and metrics. The way it works is the measured RPS is the sum of the RPS rate of each of the specified hostnames. This value is further modified by the weight parameter explained below.
### Metric weighting based on backend
There are ingress-controllers, like skipper-ingress, that supports sending traffic to different backends based on some kind of configuration, in case of skipper annotations
present on the `Ingress` object, or weights on the RouteGroup backends. By
default the number of replicas will be calculated based on the full traffic
served by these components. If however only the traffic being routed to
a specific hostname should be used then the weight for the configured hostname(s) might be specified via the `weight` annotation `metric-config.external.<metric-name>.request-per-second/weight` for the metric being configured.
## InfluxDB collector
The InfluxDB collector maps [Flux](https://github.com/influxdata/flux) queries to metrics that can be used for scaling.
@@ -426,7 +494,7 @@ the query name which will be associated with the result of the query. This
allows having multiple flux queries associated with a single HPA.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -514,7 +582,7 @@ This is an example of an HPA that will scale based on the length of an SQS
queue.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -566,7 +634,7 @@ This is an example of an HPA that will scale based on the specified value
exposed by a ZMON check with id `1234`.
```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
@@ -646,6 +714,93 @@ you need to define a `key` or other `tag` with a "star" query syntax like
metric label definitions. If both annotations and corresponding label is
defined, then the annotation takes precedence.
## Nakadi collector
The Nakadi collector allows scaling based on [Nakadi](https://nakadi.io/)
Subscription API stats metrics `consumer_lag_seconds` or `unconsumed_events`.
### Supported metrics
| Metric Type | Description | Type | K8s Versions |
- description:Whether one or more schedules are currently active.
jsonPath:.status.active
name:Active
type:boolean
name:v1
schema:
openAPIV3Schema:
description:ClusterScalingSchedule describes a cluster scoped time based
metric to be used in autoscaling operations.
description:|-
ClusterScalingSchedule describes a cluster scoped time based metric
to be used in autoscaling operations.
properties:
apiVersion:
description:'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description:|-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type:string
kind:
description:'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description:|-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type:string
metadata:
type:object
@@ -42,22 +52,32 @@ spec:
format:int64
type:integer
schedules:
description:Schedules is the list of schedules for this ScalingSchedule
description:|-
Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
to the same metric. New metrics require a new ScalingSchedule
resource.
items:
description:Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description:Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
description:|-
Defines the starting date of a OneTime schedule. It has to
be a RFC3339 formatted date.
format:date-time
type:string
durationMinutes:
description:The duration in minutes that the configured value
will be returned for the defined schedule.
description:|-
The duration in minutes (default 0) that the configured value will be
returned for the defined schedule.
type:integer
endDate:
description:|-
Defines the ending date of a OneTime schedule. It must be
a RFC3339 formatted date.
format:date-time
type:string
period:
description:Defines the details of a Repeating schedule.
properties:
@@ -76,13 +96,18 @@ spec:
- Sat
type:string
type:array
endTime:
description:The endTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
startTime:
description:The startTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
timezone:
description:The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
description:|-
The location name corresponding to a file in the IANA
Time Zone database, like Europe/Berlin.
type:string
required:
- days
@@ -90,7 +115,8 @@ spec:
- timezone
type:object
type:
description:Defines if the schedule is a OneTime schedule or
description:|-
Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
@@ -103,7 +129,6 @@ spec:
format:int64
type:integer
required:
- durationMinutes
- type
- value
type:object
@@ -111,14 +136,20 @@ spec:
required:
- schedules
type:object
status:
description:ScalingScheduleStatus is the status section of the ScalingSchedule.
properties:
active:
default:false
description:|-
Active is true if at least one of the schedules defined in the
- description:Whether one or more schedules are currently active.
jsonPath:.status.active
name:Active
type:boolean
name:v1
schema:
openAPIV3Schema:
description:ClusterScalingSchedule describes a cluster scoped time based
metric to be used in autoscaling operations.
description:|-
ClusterScalingSchedule describes a cluster scoped time based metric
to be used in autoscaling operations.
properties:
apiVersion:
description:'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description:|-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type:string
kind:
description:'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description:|-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type:string
metadata:
type:object
spec:
description:ScalingScheduleSpec is the spec part of the ScalingSchedule.
properties:
scalingWindowDurationMinutes:
description:Fade the scheduled values in and out over this many minutes.
If unset, the default per-cluster value will be used.
format:int64
type:integer
schedules:
description:Schedules is the list of schedules for this ScalingSchedule
description:|-
Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
to the same metric. New metrics require a new ScalingSchedule
resource.
items:
description:Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description:Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
description:|-
Defines the starting date of a OneTime schedule. It has to
be a RFC3339 formatted date.
format:date-time
type:string
durationMinutes:
description:The duration in minutes that the configured value
will be returned for the defined schedule.
description:|-
The duration in minutes (default 0) that the configured value will be
returned for the defined schedule.
type:integer
endDate:
description:|-
Defines the ending date of a OneTime schedule. It must be
a RFC3339 formatted date.
format:date-time
type:string
period:
description:Defines the details of a Repeating schedule.
properties:
@@ -71,13 +96,18 @@ spec:
- Sat
type:string
type:array
endTime:
description:The endTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
startTime:
description:The startTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
timezone:
description:The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
description:|-
The location name corresponding to a file in the IANA
Time Zone database, like Europe/Berlin.
type:string
required:
- days
@@ -85,7 +115,8 @@ spec:
- timezone
type:object
type:
description:Defines if the schedule is a OneTime schedule or
description:|-
Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
@@ -95,9 +126,9 @@ spec:
value:
description:The metric value that will be returned for the
defined schedule.
format:int64
type:integer
required:
- durationMinutes
- type
- value
type:object
@@ -105,15 +136,21 @@ spec:
required:
- schedules
type:object
status:
description:ScalingScheduleStatus is the status section of the ScalingSchedule.
properties:
active:
default:false
description:|-
Active is true if at least one of the schedules defined in the
- description:Whether one or more schedules are currently active.
jsonPath:.status.active
name:Active
type:boolean
name:v1
schema:
openAPIV3Schema:
description:ScalingSchedule describes a namespaced time based metric to be
used in autoscaling operations.
description:|-
ScalingSchedule describes a namespaced time based metric to be used
in autoscaling operations.
properties:
apiVersion:
description:'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description:|-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type:string
kind:
description:'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description:|-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type:string
metadata:
type:object
spec:
description:ScalingScheduleSpec is the spec part of the ScalingSchedule.
properties:
scalingWindowDurationMinutes:
description:Fade the scheduled values in and out over this many minutes.
If unset, the default per-cluster value will be used.
format:int64
type:integer
schedules:
description:Schedules is the list of schedules for this ScalingSchedule
description:|-
Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
to the same metric. New metrics require a new ScalingSchedule
resource.
items:
description:Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description:Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
description:|-
Defines the starting date of a OneTime schedule. It has to
be a RFC3339 formatted date.
format:date-time
type:string
durationMinutes:
description:The duration in minutes that the configured value
will be returned for the defined schedule.
description:|-
The duration in minutes (default 0) that the configured value will be
returned for the defined schedule.
type:integer
endDate:
description:|-
Defines the ending date of a OneTime schedule. It must be
a RFC3339 formatted date.
format:date-time
type:string
period:
description:Defines the details of a Repeating schedule.
properties:
@@ -71,13 +98,18 @@ spec:
- Sat
type:string
type:array
endTime:
description:The endTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
startTime:
description:The startTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
timezone:
description:The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
description:|-
The location name corresponding to a file in the IANA
Time Zone database, like Europe/Berlin.
type:string
required:
- days
@@ -85,7 +117,8 @@ spec:
- timezone
type:object
type:
description:Defines if the schedule is a OneTime schedule or
description:|-
Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
@@ -95,9 +128,9 @@ spec:
value:
description:The metric value that will be returned for the
defined schedule.
format:int64
type:integer
required:
- durationMinutes
- type
- value
type:object
@@ -105,15 +138,21 @@ spec:
required:
- schedules
type:object
status:
description:ScalingScheduleStatus is the status section of the ScalingSchedule.
properties:
active:
default:false
description:|-
Active is true if at least one of the schedules defined in the
- description:Whether one or more schedules are currently active.
jsonPath:.status.active
name:Active
type:boolean
name:v1
schema:
openAPIV3Schema:
description:ScalingSchedule describes a namespaced time based metric to be
used in autoscaling operations.
description:|-
ScalingSchedule describes a namespaced time based metric to be used
in autoscaling operations.
properties:
apiVersion:
description:'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description:|-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type:string
kind:
description:'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description:|-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type:string
metadata:
type:object
@@ -42,22 +54,32 @@ spec:
format:int64
type:integer
schedules:
description:Schedules is the list of schedules for this ScalingSchedule
description:|-
Schedules is the list of schedules for this ScalingSchedule
resource. All the schedules defined here will result on the value
to the same metric. New metrics require a new ScalingSchedule resource.
to the same metric. New metrics require a new ScalingSchedule
resource.
items:
description:Schedule is the schedule details to be used inside
a ScalingSchedule.
properties:
date:
description:Defines the starting date of a OneTime schedule.
It has to be a RFC3339 formated date.
description:|-
Defines the starting date of a OneTime schedule. It has to
be a RFC3339 formatted date.
format:date-time
type:string
durationMinutes:
description:The duration in minutes that the configured value
will be returned for the defined schedule.
description:|-
The duration in minutes (default 0) that the configured value will be
returned for the defined schedule.
type:integer
endDate:
description:|-
Defines the ending date of a OneTime schedule. It must be
a RFC3339 formatted date.
format:date-time
type:string
period:
description:Defines the details of a Repeating schedule.
properties:
@@ -76,13 +98,18 @@ spec:
- Sat
type:string
type:array
endTime:
description:The endTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
startTime:
description:The startTime has the format HH:MM
pattern:(([0-1][0-9])|([2][0-3])):([0-5][0-9])
type:string
timezone:
description:The location name corresponding to a file in
the IANA Time Zone database, like Europe/Berlin.
description:|-
The location name corresponding to a file in the IANA
Time Zone database, like Europe/Berlin.
type:string
required:
- days
@@ -90,7 +117,8 @@ spec:
- timezone
type:object
type:
description:Defines if the schedule is a OneTime schedule or
description:|-
Defines if the schedule is a OneTime schedule or
Repeating one. If OneTime, date has to be defined. If Repeating,
Period has to be defined.
enum:
@@ -103,7 +131,6 @@ spec:
format:int64
type:integer
required:
- durationMinutes
- type
- value
type:object
@@ -111,14 +138,20 @@ spec:
required:
- schedules
type:object
status:
description:ScalingScheduleStatus is the status section of the ScalingSchedule.
properties:
active:
default:false
description:|-
Active is true if at least one of the schedules defined in the
// ScalingScheduleList is a list of namespaced scaling schedules.
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.