Skip to content

Metrics.k8s.io API

The metrics.k8s.io API (specifically v1beta1.metrics.k8s.io) is the resource Metrics endpoint provided by the Kubernetes Metrics Server.^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md] It enables the cluster to expose CPU and memory usage statistics for pods and nodes, which are not available through the standard Kubernetes core APIs.^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]

This API is implemented by deploying Metrics Server, a cluster-level data aggregator, which registers itself as an [[APIService]].^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]

Access and Usage

Users interact with the Metrics data primarily through the command-line interface using the kubectl top command^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]. This command queries the Metrics API to provide a snapshot of current resource utilization.

  • Node Metrics: To view CPU and memory usage for all nodes in the cluster:
    [kubectl](<./kubectl.md>) top node
    
  • Pod Metrics: To view usage for pods within a specific namespace:
    [kubectl](<./kubectl.md>) top pods -n <namespace>
    

Permissions

Accessing the Metrics API requires specific permissions within the cluster. The Metrics Server Installation typically includes a ClusterRole named system:aggregated-metrics-reader which authorizes the reading of Metrics resources^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

The allowed resources and verbs under the metrics.k8s.io API group generally include^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]:

  • Resources: pods, nodes
  • Verbs: get, list, watch

Data Characteristics

The Metrics exposed through this API are real-time Metrics collected from the kubelet summary API^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md]. Because the Metrics Server stores this data in memory, historical data is not preserved; Metrics are reset if the server restarts^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

Role in Automation

The metrics.k8s.io API is a prerequisite for cluster automation features such as [[AutoScaling]]. Without these Metrics, the Horizontal Pod Autoscaler (HPA) cannot determine when to scale applications based on CPU or memory load^[400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md].

Sources

  • 400-devops__06-Kubernetes__k8s-ithelp__Day24__README.md