An implementation of the custom.metrics.k8s.io API using Prometheus
Find a file
huxiaoliang af1dcc0cda Add support for auth when connecting to Prometheus
Currently, the adapter uses http.DefaultClient to access Prometheus.
This means that it does support using TLS client certificates, custom
CA certificates, or token-base authentication, which are all common
setups when connecting to Prometheus behind an auth proxy.

This commit adds support for using a separate kubeconfig, or in-cluster
config, to configure auth when connecting to Prometheus.

Fixes #52

[directxman12: cleanups, spelling corrections, and slight refactor]
2018-03-22 12:07:28 -04:00
cmd/adapter Add support for auth when connecting to Prometheus 2018-03-22 12:07:28 -04:00
deploy [deploy] update types to Kube 1.9 versions 2018-02-13 13:25:13 -05:00
docs Merge pull request #47 from aschepis/patch-1 2018-02-22 14:28:33 -05:00
hack [build] Add gofmt-related Makefile targets 2017-06-27 19:01:39 -04:00
pkg Allow setting a resource label prefix 2018-02-06 14:35:40 -05:00
.gitignore [build] fix build makefile target path 2017-06-26 16:27:26 -04:00
.travis-deploy.sh [infra] automatically publish new images 2018-02-28 14:22:09 -05:00
.travis.yml [infra] automatically publish new images 2018-02-28 14:22:09 -05:00
glide.lock Update deps for Kubernetes 1.8 2017-09-28 17:10:11 -04:00
glide.yaml Update deps for Kubernetes 1.8 2017-09-28 17:10:11 -04:00
Makefile Use rm -rf instead of sudo when removing the temp dir 2018-01-23 13:35:02 +02:00
README.md [docs] update to v1.9 API versions 2018-02-13 13:16:14 -05: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.

  • --rate-interval=<duration>: This is the duration used when requesting rate metrics from Prometheus. It must be larger than your Prometheus collection interval.

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

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.

In general:

  • Metrics must have the namespace label to be considered.

  • For each label on a metric, if that label name corresponds to a Kubernetes resource (like pod or service), the metric will be associated with that resource.

  • Metrics ending in _total are assumed to be cumulative, and will be exposed without the suffix as a rate metric.

Detailed information can be found under docs/format.md.

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.

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