Hello and welcome to this lecture. In this lecture
we talk about Monitoring a Kubernetes cluster.
So how do you monitor resource consumption on Kubernetes? Or more importantly what would you like
to monitor?
I’d like to know Node level metrics such as the number of nodes in the cluster,
how many of them are healthy as well as performance metrics such as CPU. Memory, network and disk utilization.
As well as POD level metrics such as the number of PODs, and performance metrics of each POD such
as the CPU and Memory consumption on them.
So we need a solution that will monitor these metrics store them and provide analytics around this data
As of this recording, Kubernetes does not come with a full featured built-in monitoring solution.
However, there are a number of open-source solutions available today, such as the Metrics-Server, Prometheus,
Elastic Stack, and proprietary solutions like Datadog and Dynatrace.
Heapster was one of the original projects that enabled monitoring and analysis features for kubernetes
You will see a lot of reference online when you look for reference architectures on monitoring Kubernetes.
However, Heapster is now Deprecated and a slimmed down version was formed known as the Metrics Server.
You can have one metrics server per kubernetes cluster the metric server retrieves metrics from each
of the kubernetes nodes and pods, aggregates them and stores them in memory.
Note that the metric server is only an in memory monitoring solution and does not store the metrics
on the desk and as a result you cannot see historical performance data.
For that you must rely on one of the advanced monitoring solutions we talked about earlier in this lecture.
So how are the metrics generated for the PODs on these nodes? Kubernetes
runs an agent on each node known as the kubelet, which is responsible for receiving instructions
from the kubernetes API master server and running PODs on the nodes.
The kubelet also contains a subcomponent known as as cAdvisor or Container Advisor. cAdvisor is
responsible for retrieving performance metrics from pods, and exposing them through the kubelet API
to make the metrics available for the Metrics Server. If you are using minikube for your local cluster,
run the command minikube
addons enable metrics-server. For all other environments deploy the metrics server by cloning the
metrics-server deployment files from the github repository. And then deploying the required components
using the kubectl create command. This command deploys a set of pods, services and roles to enable
metrics server to poll for performance metrics from the nodes in the cluster.
Once deployed, give the metrics-server some time to collect and process data. Once processed, cluster performance
can be viewed by running the command kubectl top node.
This provides the CPU and Memory consumption of each of the nodes. As you can see 8% of the CPU
on my master node is consumed, which is about 166 milli cores.
Use the kubectl top pod command to view performance metrics of pods in kubernetes.
That's it for this lecture.
Head over to the coding exercises section and practice viewing performance metrics on the kubernetes
cluster.
Thank you.