To monitor resource consumption in kubernetes.For Example, to monitor nodel level metrics such as the number of nodes in the clusters, how many are healthy and performance metrics such as CPU, memory and dissk utilization., as well as pod level metrics such as number of pods and performance metrics such as CPU and memory utilization.
We need a solution that monitors these metrics, store them and provide analytics around this data.
Kubernetes does not come with a full featured monitoring solution, however there are a number of open source solutions available such as metrics server, Prometheus, Elastic Stack, Data Dog, dynatrace.
Heapster was one of the original projects that enabled monitoring and analysis features for kubernetes.
However, Heapster is now deprecated and a slimmed down version was formed known as the Metric Server.
The Metrics server
receives metrics from each of the kubernetes nodes and pods, aggregates them and stores them in memory.
Metrics server is only an in-memory
monitoring solution and does not store the memory on the disk. Therefore, we cannot historical performance data. For this, we must rely on advanced monitoring solutions such as Prometheus, Elastic Stack, Data Dog, dynatrace.
kubernetes runs an agent on each node known as kubelet
which is responsible for receiving instructions from the kubernetes api master server and running pods on the nodes.
The kubelet also contains a sub component known as cAdvisor
or Container Advisor
.
The cAdvisor
is responsible for receiving performance metrics from pods and exposing them through the kublet api to meet the metrics available for the metrics server.
Deploy the metrics server
In minikube - minikube addons enable metrics-server
In other environments - git clone https://github.com/kubernetes-incubator/metrice-serve
then kubectl create -f deploy/1.8+/
This commands deploys specific roles, services that enables metrics server.
Cluster performance can be viewed
kubectl top node
This provides the CPU and memory consumption of each of the nodes.
kubectl top pod
To view performance metrics of pods.