Framework for implementing custom metrics support for Kubernetes
Clone or download
Latest commit bb8bae1 Nov 26, 2018

Custom Metrics Adapter Server Boilerplate


This repository contains boilerplate code for setting up an implementation of the custom metrics API (

It includes the necessary boilerplate for setting up an implementation (generic API server setup, registration of resources, etc), plus an implementation for testing that allows setting metric values over HTTP.

How to use this repository

This repository is designed to be used as a library. First, implement one or more of the metrics provider interfaces in pkg/provider (for example, CustomMetricsProvider), depending on which APIs you want to support.

Then, use the AdapterBase in pkg/cmd to initialize the necessary flags and set up the API server, passing in your providers.

More information can be found in the getting started guide, and the testing implementation can be found in the test-adapter directory.

It is strongly suggested that you make use of the dependency versions listed in glide.yaml, as mismatched versions of Kubernetes dependencies can lead to build issues.

Development for boilerplate project


Clone and Build the Testing Adapter

There is a test adapter in this repository that can be used for testing changes to the repository, as a mock implementation of the APIs for automated unit tests, and also as an example implementation.

Note that this adapter should not be used for production. It's for writing automated e2e tests and serving as a sample only.

To build and deploy it:

# build the test-adapter container as $REGISTRY/k8s-test-metrics-adapter
export REGISTRY=<some-prefix>
make test-adapter-container

# push the container up to a registry (optional if your cluster is local)
docker push $REGISTRY/k8s-test-metrics-adapter

# launch the adapter using the test adapter deployment files
kubectl apply -f test-adapter-deploy/testing-adapter.yaml

After the deployment you can set new metrics on the adapter using query the testing adapter with:

# set up a proxy to the api server so we can access write endpoints
# of the testing adapter directly
kubectl proxy &
# write a sample metric -- the write paths match the same URL structure
# as the read paths, but at the /write-metrics base path.
curl -XPOST http://localhost:8080/api/v1/namespaces/custom-metrics/services/custom-metrics-apiserver:http/proxy/write-metrics/namespaces/default/services/kubernetes/test-metric --data-raw '"300m"'
# you can pipe to `jq .` to pretty-print the output, if it's installed
# (otherwise, it's not necessary)
kubectl get --raw "/apis/" | jq .


The APIs in this repository follow the standard guarantees for Kubernetes APIs, and will follow Kubernetes releases.

Community, discussion, contribution, and support

Learn how to engage with the Kubernetes community on the community page.

You can reach the maintainers of this repository at:

Code of Conduct

Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.

Contribution Guidelines

See for more information.