Skip to content

Commit 3544741

Browse files
Update README, mention external metrics
1 parent 41ec178 commit 3544741

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

README.md

+39-26
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Custom Metrics Adapter Server Boilerplate
22

3+
[![Go Reference](https://pkg.go.dev/badge/sigs.k8s.io/custom-metrics-apiserver.svg)](https://pkg.go.dev/sigs.k8s.io/custom-metrics-apiserver)
4+
35
## Purpose
46

57
This repository contains boilerplate code for setting up an implementation
6-
of the custom metrics API (https://github.com/kubernetes/metrics).
8+
of the [Metrics APIs](https://github.com/kubernetes/metrics):
9+
10+
- Custom metrics (`k8s.io/metrics/pkg/apis/custom_metrics`)
11+
- External metrics (`k8s.io/metrics/pkg/apis/external_metrics`)
712

813
It includes the necessary boilerplate for setting up an implementation
914
(generic API server setup, registration of resources, etc), plus an
10-
implementation for testing that allows setting metric values over HTTP.
15+
implementation for testing that allows setting custom metric values over HTTP.
1116

1217
## How to use this repository
1318

@@ -22,60 +27,62 @@ More information can be found in the [getting started
2227
guide](/docs/getting-started.md), and the testing implementation can be
2328
found in the [test-adapter directory](/test-adapter).
2429

25-
## Development for boilerplate project
26-
27-
### Pre-reqs
30+
### Prerequisites
2831

29-
- [Go](https://golang.org/doc/install) same version of [Go as Kubernetes](https://github.com/kubernetes/community/blob/master/contributors/devel/development.md#go)
30-
- [git](https://git-scm.com/downloads)
32+
[Go](https://go.dev/doc/install): this library requires the same version of
33+
[Go as Kubernetes](https://git.k8s.io/community/contributors/devel/development.md#go).
3134

32-
### Clone and Build the Testing Adapter
35+
## Test Adapter
3336

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

38-
Note that this adapter *should not* be used for production. It's for
41+
Note that this adapter **should not** be used for production. It's for
3942
writing automated e2e tests and serving as a sample only.
4043

4144
To build and deploy it:
4245

4346
```bash
44-
# build the test-adapter container as $REGISTRY/k8s-test-metrics-adapter
47+
# build the test-adapter container as $REGISTRY/k8s-test-metrics-adapter-amd64
4548
export REGISTRY=<some-prefix>
4649
make test-adapter-container
4750

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

51-
# launch the adapter using the test adapter deployment files
54+
# launch the adapter using the test adapter deployment manifest
5255
kubectl apply -f test-adapter-deploy/testing-adapter.yaml
5356
```
5457

55-
After the deployment you can set new metrics on the adapter using
56-
query the testing adapter with:
58+
When the deployment is ready, you can define new metrics on the test adapter
59+
by querying the write endpoint:
5760

5861
```bash
59-
# set up a proxy to the api server so we can access write endpoints
62+
# set up a proxy to the API server so we can access write endpoints
6063
# of the testing adapter directly
6164
kubectl proxy &
6265
# write a sample metric -- the write paths match the same URL structure
6366
# as the read paths, but at the /write-metrics base path.
6467
# data needs to be in json, so we also need to set the content-type header
65-
curl -XPOST -H 'Content-Type: application/json' http://localhost:8001/api/v1/namespaces/custom-metrics/services/custom-metrics-apiserver:http/proxy/write-metrics/namespaces/default/services/kubernetes/test-metric --data-raw '"300m"'
68+
curl -X POST \
69+
-H 'Content-Type: application/json' \
70+
http://localhost:8001/api/v1/namespaces/custom-metrics/services/custom-metrics-apiserver:http/proxy/write-metrics/namespaces/default/services/kubernetes/test-metric \
71+
--data-raw '"300m"'
6672
```
6773

6874
```bash
6975
# you can pipe to `jq .` to pretty-print the output, if it's installed
7076
# (otherwise, it's not necessary)
71-
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq .
77+
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta2" | jq .
7278
# fetching certain custom metrics of namespaced resources
73-
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/services/kubernetes/test-metric" | jq .
79+
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta2/namespaces/default/services/kubernetes/test-metric" | jq .
7480
```
7581

7682
If you wanted to target a simple nginx-deployment and then use this as an HPA scaler metric, something like this would work following the previous curl command:
77-
```
78-
apiVersion: autoscaling/v2beta2
83+
84+
```yaml
85+
apiVersion: autoscaling/v2
7986
kind: HorizontalPodAutoscaler
8087
metadata:
8188
name: nginx-deployment
@@ -101,22 +108,28 @@ spec:
101108
value: 300m
102109
```
103110
111+
You can also query the external metrics:
112+
113+
```bash
114+
kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1" | jq .
115+
# fetching certain custom metrics of namespaced resources
116+
kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/my-external-metric" | jq .
117+
```
118+
104119
## Compatibility
105120

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

109124
## Community, discussion, contribution, and support
110125

111-
Learn how to engage with the Kubernetes community on the [community
112-
page](http://kubernetes.io/community/).
126+
Learn how to engage with the Kubernetes community on the
127+
[community page](https://kubernetes.io/community/).
113128

114129
You can reach the maintainers of this repository at:
115130

116-
- Slack: #sig-instrumentation (on https://kubernetes.slack.com -- get an
117-
invite at slack.kubernetes.io)
118-
- Mailing List:
119-
https://groups.google.com/forum/#!forum/kubernetes-sig-instrumentation
131+
- [Slack](https://slack.k8s.io/): channel `#sig-instrumentation`
132+
- [Mailing List](https://groups.google.com/g/kubernetes-sig-instrumentation)
120133

121134
### Code of Conduct
122135

test-adapter-deploy/testing-adapter.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ spec:
133133
groupPriorityMinimum: 100
134134
versionPriority: 200
135135
---
136+
apiVersion: apiregistration.k8s.io/v1
137+
kind: APIService
138+
metadata:
139+
name: v1beta1.external.metrics.k8s.io
140+
spec:
141+
service:
142+
name: custom-metrics-apiserver
143+
namespace: custom-metrics
144+
group: external.metrics.k8s.io
145+
version: v1beta1
146+
insecureSkipTLSVerify: true
147+
groupPriorityMinimum: 100
148+
versionPriority: 100
149+
---
136150
apiVersion: rbac.authorization.k8s.io/v1
137151
kind: ClusterRole
138152
metadata:

0 commit comments

Comments
 (0)