Logging and Monitoring in Kubernetes
Metrics Server
You can have one Metrics Server per Kubernetes cluster.
The Metrics Server retrieves 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 metrics on the disk. Due to this, you cannot see historical performance data.
How does it work?
Kubernetes runs an agent on each node known as kubelet, which is responsible for receiving instructions from Kube-APIServer and running pods on the nodes.
The kubelet also contains a sub-component known as cAdvisor or Container Advisor.
cAdvisor is responsible for retrieving performance metrics from pods and exposing them through kubelet API to make the metrics available for the Metrics Server.
kubectl top nodes/pods
- to view the metrics of nodes/pods.
Managing Application Logs
We can view logs in Kubernetes using
kubectl logs -f <pod_name>
. Here-f
option is to view the live logs of a container.But if we have multiple containers inside a pod (multi-container pod), then at that time we have to specify the container name as well in the logs command to view the logs specific to those containers. If not done so, Kubernetes will throw an error.
kubectl logs -f <pod_name> <container_name>
Subscribe to my newsletter
Read articles from Rohit Pagote directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Rohit Pagote
Rohit Pagote
I am an aspiring DevOps Engineer proficient with containers and container orchestration tools like Docker, Kubernetes along with experienced in Infrastructure as code tools and Configuration as code tools, Terraform, Ansible. Well-versed in CICD tool - Jenkins. Have hands-on experience with various AWS and Azure services. I really enjoy learning new things and connecting with people across a range of industries, so don't hesitate to reach out if you'd like to get in touch.