An implementation of the custom.metrics.k8s.io API using Prometheus
Find a file
Joel Speed 6089fa8528 Use channel for series aggregation
This fixes asynchronous read/write issues to when performing series
discovery by pushing series results onto a channel, instead of trying to
write them directly to a map.
2018-06-27 16:56:20 -04:00
cmd Add a helper to generate legacy configuration 2018-06-27 16:56:20 -04:00
deploy Add a helper to generate legacy configuration 2018-06-27 16:56:20 -04:00
docs Advanced Config Docs Updates 2018-06-27 16:56:20 -04:00
hack [build] Add gofmt-related Makefile targets 2017-06-27 19:01:39 -04:00
pkg Use channel for series aggregation 2018-06-27 16:56:20 -04:00
.gitignore Advanced Configuration 2018-06-22 15:37:12 -04:00
.travis-deploy.sh [infra] automatically publish new images 2018-02-28 14:22:09 -05:00
.travis.yml Switch to dep for dependency management 2018-06-22 16:06:12 -04:00
Gopkg.lock Switch to dep for dependency management 2018-06-22 16:06:12 -04:00
Gopkg.toml Switch to dep for dependency management 2018-06-22 16:06:12 -04:00
LICENSE Fix license issue 2018-03-15 17:31:27 +08:00
Makefile Switch to dep for dependency management 2018-06-22 16:06:12 -04:00
README.md Advanced Config Docs Updates 2018-06-27 16:56:20 -04:00

Kubernetes Custom Metrics Adapter for Prometheus

Build Status

This repository contains an implementation of the Kubernetes custom metrics API (custom.metrics.k8s.io/v1beta1), suitable for use with the autoscaling/v2 Horizontal Pod Autoscaler in Kubernetes 1.6+.

Configuration

The adapter takes the standard Kubernetes generic API server arguments (including those for authentication and authorization). By default, it will attempt to using Kubernetes in-cluster config to connect to the cluster.

It takes the following addition arguments specific to configuring how the adapter talks to Prometheus and the main Kubernetes cluster:

  • --lister-kubeconfig=<path-to-kubeconfig>: This configures how the adapter talks to a Kubernetes API server in order to list objects when operating with label selectors. By default, it will use in-cluster config.

  • --metrics-relist-interval=<duration>: This is the interval at which to update the cache of available metrics from Prometheus.

  • --prometheus-url=<url>: This is the URL used to connect to Prometheus. It will eventually contain query parameters to configure the connection.

  • --config=<yaml-file> (-c): This configures how the adapter discovers available Prometheus metrics and the associated Kubernetes resources, and how it presents those metrics in the custom metrics API. More information about this file can be found in docs/config.md.

Presentation

The adapter gathers the names of available metrics from Prometheus a regular interval (see Configuration above), and then only exposes metrics that follow specific forms.

The rules governing this discovery are specified in a configuration file. If you were relying on the implicit rules from the previous version of the adapter, you can use the included config-gen tool to generate a configuration that matches the old implicit ruleset:

$ go run cmd/config-gen main.go [--rate-interval=<duration>] [--label-prefix=<prefix>]

Example

A brief walkthrough exists in docs/walkthrough.md.

Additionally, @luxas has an excellent example deployment of Prometheus, this adapter, and a demo pod which serves a metric http_requests_total, which becomes the custom metrics API metric pods/http_requests. It also autoscales on that metric using the autoscaling/v2beta1 HorizontalPodAutoscaler. Note that @luxas's tutorial uses a slightly older version of the adapter.

It can be found at https://github.com/luxas/kubeadm-workshop. Pay special attention to: