Coder Social home page Coder Social logo

sanwishe / custom-metrics-apiserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kubernetes-sigs/custom-metrics-apiserver

0.0 1.0 0.0 34.74 MB

Framework for implementing custom metrics support for Kubernetes

License: Apache License 2.0

Go 97.52% Makefile 1.58% Shell 0.84% Dockerfile 0.06%

custom-metrics-apiserver's Introduction

Custom Metrics Adapter Server Boilerplate

Purpose

This repository contains boilerplate code for setting up an implementation of the custom metrics API (https://github.com/kubernetes/metrics).

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.

Development for boilerplate project

Pre-reqs

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.
# data needs to be in json, so we also need to set the content-type header
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"'
# you can pipe to `jq .` to pretty-print the output, if it's installed
# (otherwise, it's not necessary)
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq .

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:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: nginx-deployment
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx-deployment
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Object
    object:
      metric:
        name: test-metric
      describedObject:
        apiVersion: v1
        kind: Service
        name: kubernetes
      target:
        type: Value
        value: 300m

Compatibility

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 CONTRIBUTING.md for more information.

custom-metrics-apiserver's People

Contributors

directxman12 avatar k8s-ci-robot avatar dgrisonnet avatar jsturtevant avatar kawych avatar johanneswuerbach avatar astefanutti avatar s-urbaniak avatar mbssaiakhil avatar alb0t avatar yangjunmyfm192085 avatar dashanji avatar answer1991 avatar wanlinghao avatar srinivasrk avatar skydiator avatar mirake avatar 44past4 avatar uthark avatar damemi avatar luxas avatar fj avatar ydcool avatar arajkumar avatar arjunrn avatar spiffxp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.