Metrics Server

What is Metrics-Server?

Metrics-Server is a scalable, efficient source of container resource metrics for Kubernetes built-in autoscaling pipelines.

Metrics Server collects resource metrics from Kubelets and exposes them in Kubernetes apiserver through Metrics API for use by Horizontal Pod Autoscaler and Vertical Pod Autoscaler. Metrics API can also be accessed by kubectl top, making it easier to debug autoscaling pipelines.

How does it works?

flowchart RL
  subgraph cluster[Cluster]
    direction RL
    S[

] A[Metrics-
Server] subgraph B[Nodes] direction TB D[cAdvisor] --> C[kubelet] E[Container
runtime] --> D E1[Container
runtime] --> D P[pod data] -.- C end L[API
server] W[HPA] C ---->|node level
resource metrics| A -->|metrics
API| L --> W end L ---> K[kubectl
top] classDef box fill:#fff,stroke:#000,stroke-width:1px,color:#000; class W,B,P,K,cluster,D,E,E1 box classDef spacewhite fill:#ffffff,stroke:#fff,stroke-width:0px,color:#000 class S spacewhite classDef k8s fill:#326ce5,stroke:#fff,stroke-width:1px,color:#fff; class A,L,C k8s

Image reference1.

metrics-server discovers all nodes on the cluster and queries each node’s kubelet for CPU and memory usage.

Kubelet acts as a bridge between the Kubernetes master and the nodes, managing the pods and containers running on a machine. The kubelet translates each pod into its constituent containers and fetches individual container usage statistics from the container runtime through the container runtime interface.

When using a container runtime that uses Linux cgroups and namespaces to implement containers, and the container runtime does not publish usage statistics, then the kubelet can look up those statistics directly (using code from cAdvisor).

Kubelet exposes the aggregated pod resource usage statistics through the metrics-server Resource Metrics API. This API is served at /metrics/resource/v1beta1 on the kubelet’s authenticated and read-only ports.

Metric-Server as K3s add-on

K3s install by default Metric-server using a set of manifest files, as add-on.

K3s Embedded Metric server installation. It can be disable, using k3s installation option --disable metrics-server, and instead, it manually installed it using Helm chart, so version installed and configuration options can be better controlled

Installation

Using Metrics-Server Helm Chart

  • Add Git repo

    helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
    
  • Install helm chart in kube-system namespace ```shell helm upgrade –install metrics-server metrics-server/metrics-server

  1. https://kubernetes.io/docs/tasks/debug/debug-cluster/resource-metrics-pipeline/ 


Last Update: Oct 06, 2024

Comments: