Metrics-server has a built-in API endpoint where current usage of resources is reflected, and can be accessed with a client library or proxying the master endpoints, for instance via kubectl proxy
to expose the metrics in localhost or k get --raw "/apis/metrics.k8s.io/v1beta1/pods" |jq .
to get a JSON result (with jq
previously installed).
Keep in mind that metric aggregation is not supported yet in this API. Usually, these are collected by a third-party agent and aggregated in a separate backend, for example, Stackdriver monitoring or Datadog.
Now, for the specific information you want to fetch from your cluster, there is no metric specific for the number of replicas created by the HPA. The system uses the resource usage metric in order to determine when to spawn more replicas of a deployment.
The CPU usage case seems very specific for already aggregated metrics, so you can use an aggregation solution for Kubernetes, like the ones mentioned before.
Finally, there is also not specific metric for failures and this specific information doesn't seem to be part of any metrics pipeline but rather logging, as failures usually get logged but can be aggregated afterwards to create metrics.