custom-metrics-apiserver-simulator

module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT

README

custom-metrics-apiserver-simulator

Create Cluster

kwokctl create cluster --runtime docker
kwokctl scale node --replicas 2

Set up apiservice and service

kubectl apply -k ./kustomize/apiservice
kubectl create service externalname custom-metrics-apiserver -n kube-system --external-name host.docker.internal

Set up CRD and Start Custom Metrics Simulator

kubectl apply -k ./kustomize/crd
go run ./cmd/custom-metrics-apiserver-simulator

Test

Custom Metrics With HPA
kubectl apply -f ./test/custom_metrics.yaml
$ kubectl get --raw '/apis/custom.metrics.k8s.io/v1beta2/namespaces/default/pods/*/http_requests_total' | jq .
{
  "kind": "MetricValueList",
  "apiVersion": "custom.metrics.k8s.io/v1beta2",
  "metadata": {},
  "items": [
    {
      "describedObject": {
        "kind": "Pod",
        "namespace": "default",
        "name": "custom-metric-54d77dbf95-fgq8d",
        "apiVersion": "/v1"
      },
      "metric": {
        "name": "http_requests_total",
        "selector": null
      },
      "timestamp": "2023-09-14T05:30:39Z",
      "value": "900m"
    },
    {
      "describedObject": {
        "kind": "Pod",
        "namespace": "default",
        "name": "custom-metric-54d77dbf95-kq45w",
        "apiVersion": "/v1"
      },
      "metric": {
        "name": "http_requests_total",
        "selector": null
      },
      "timestamp": "2023-09-14T05:30:39Z",
      "value": "900m"
    }
  ]
}
External Metrics With HPA
kubectl apply -f ./test/external_metrics.yaml
$ kubectl get --raw '/apis/external.metrics.k8s.io/v1beta1/namespaces/default/my_external_metric' | jq .
{
  "kind": "ExternalMetricValueList",
  "apiVersion": "external.metrics.k8s.io/v1beta1",
  "metadata": {},
  "items": [
    {
      "metricName": "my_external_metric",
      "metricLabels": null,
      "timestamp": "2023-09-14T05:31:51Z",
      "value": "100m"
    }
  ]
}

Directories

Path Synopsis
cmd
pkg
apis/v1alpha1
Package v1alpha1 implements the v1alpha1 apiVersion
Package v1alpha1 implements the v1alpha1 apiVersion
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/apis/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/apis/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL