Binding HPA to a custom made apiservice

Viewed 218

Is it possible to configure HPA to work with different api-service for custom-metrics server and not v1beta1.custom.metrics.k8s.io?

As in my case, v1beta1.custom.metrics.k8s.io already bound to some other metrics server and I don't want to touch it.

I want to create my own metrics server, bind it to my own api-service and use this api-service with HPA in my namespace.

1 Answers

You can create a HPA to any custom metrics available in your node following the guide from official docs.

In order to get the APIs available for you, metrics-server exposes metrics via APIs below:

  • /nodes - all node metrics; type []NodeMetrics
  • /nodes/{node} - metrics for a specified node; type NodeMetrics
  • /namespaces/{namespace}/pods - all pod metrics within namespace with support for all-namespaces; type []PodMetrics
  • /namespaces/{namespace}/pods/{pod} - metrics for a specified pod; type PodMetrics

Full command to list available APIs looks like:

kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1"

In case you are working on GCP or other cloud, there is a guide for Deploying the Custom Metrics in GCP


UPDATE

Answering to your comments:

HPA able to read metrics from:

  • metrics.k8s.io (resource metrics)
  • custom.metrics.k8s.io(custom metrics)
  • external.metrics.k8s.io(external metrics)

The common use for HorizontalPodAutoscaler is to configure it to fetch metrics from aggregated APIs (metrics.k8s.io, custom.metrics.k8s.io, or external.metrics.k8s.io). The metrics.k8s.io API is usually provided by an add on named Metrics Server, which needs to be launched separately. For more information about resource metrics, see Metrics Server.

So, you can take anything from metrics.k8s.io that is available to your cluster. Or you can create your own APIService:

apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  name: <name of the registration object>
spec:
  group: <API group name this extension apiserver hosts>
  version: <API version this extension apiserver hosts>
  groupPriorityMinimum: <priority this APIService for this group, see API documentation>
  versionPriority: <prioritizes ordering of this version within a group, see API documentation>
  service:
    namespace: <namespace of the extension apiserver service>
    name: <name of the extension apiserver service>
  caBundle: <pem encoded ca cert that signs the server cert used by the webhook>

Please find a full guide on creating your APIService. Have fun :)

Related