Metrics server deployment for Kubernetes

The metric server is one of the components in the core metrics pipeline of Kubernetes monitoring architecture. The metric server collects metrics from Kubelets and exposes them through the Kubernetes Apiserver via its metric API. These metrics are then read by tools like kubectl top, the horizontal and vertical pod autoscaler (HPA and VPA). The metric server only stores the very latest values ​​of the metrics that are used for the core metrics pipeline (e.g. CPU, memory) and is not for forwarding metrics and third party targets.

Deploying the metrics server to your cluster is fairly easy. In order to deploy metrics-server in your cluster run the following command from the top-level directory of this repository:

kubectl apply -f deploy/kubernetes/

That’s it!

Fixing “no metrics known for node” error for kubernetes metrics server

As for me, in some cases the metrics server is unable to scrape metrics from the kubelet due to dns issues. If you encounter the following error in the logs of the metrics server

unable to fetch node metrics for node no metrics known for node

you want to add the following additional flags to the deploy/kubernetes/metrics-server-deployment.yaml file:

- name: metrics-server
    - --cert-dir=/tmp
    - --secure-port=4443
    # fix "no metrics known for node" error
    # first you need to ensure that the kubernetes node hostname can be resolved normally in the cluster dns (coredns)
    # refs:
    - --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname
    - --kubelet-insecure-tls