Starting from Kubernetes 1.8, resource usage metrics, such as container CPU and memory usage, are available in Kubernetes through the Metrics API. These metrics can be either accessed directly by user, for example by using kubectl top command, or used by a controller in the cluster, e.g. Horizontal Pod Autoscaler, to make decisions.

  • Metrics API doesn’t store the metric values, so it’s not possible for example to get the amount of resources used by a given node 10 minutes ago.
  • The URI of Metrics API is /apis/ and is defined in
  • metrics-server must be deployed to access this API

Enable API Aggregation

Before deploying metrics-server, API Aggregation must be enabled first in kube-apiserver.


And if kube-proxy is not running on the master nodes, an extra config is also required:


Deploy metrics-server

$ git clone
$ cd metrics-server
$ kubectl create -f deploy/1.8+/

Wait a while and then metrics-server pod will be running

kubectl -n kube-system get pods -l k8s-app=metrics-server

Metrics API

You can access Metrics API via kubectl proxy, e.g.


Or it can be accessed by kubectl raw:

  • kubectl get --raw apis/
  • kubectl get --raw apis/
  • kubectl get --raw apis/<node-name>
  • kubectl get --raw apis/<namespace-name>/pods/<pod-name>


If metrics-server Pod is stuck on CrashLoopBackOff and restartCount is not zero, then it's probably API Aggregation not enabled on kube-apiserver.

If there are still same issue even after enabling API Aggregation, then we should check metrics-server's logs first. You may find following error:

dial tcp i/o timeout

Which indicates the metrics-server couldn't reach kube-apiserver. It is probably because FORWARD disabled by newer docker (e.g. v1.13+), which could be enabled by

echo "ExecStartPost=/sbin/iptables -P FORWARD ACCEPT" >> /etc/systemd/system/docker.service.d/exec_start.conf
systemctl daemon-reload
systemctl restart docker


© Pengfei Ni all right reserved,powered by GitbookUpdated at 2018-04-20 06:30:31

results matching ""

    No results matching ""