Kubernetes Best Practices, 2nd Edition
by Brendan Burns, Eddie Villalba, Dave Strebel, Lachlan Evenson
Chapter 3. Monitoring and Logging in Kubernetes
In this chapter, we discuss best practices for monitoring and logging in Kubernetes. We’ll dive into the details of different monitoring patterns, important metrics to collect, and building dashboards from these raw metrics. We then wrap up with examples of implementing monitoring for your Kubernetes cluster.
Metrics Versus Logs
You first need to understand the difference between log collection and metrics collection. They are complementary but serve different purposes:
- Metrics
-
A series of numbers measured over a period of time.
- Logs
-
Logs keep track of what happens while a program is running, including any errors, warnings, or notable events that occur.
A example of where you would need to use both metrics and logging is when an application is performing poorly. Our first indication of the issue might be an alert of high latency on the pods hosting the application, but the metrics might not give a good indication of the issue. We then can look into our logs to investigate errors that are being emitted from the application.
Monitoring Techniques
Closed-box monitoring focuses on monitoring from the outside of an application and is what’s been used traditionally when monitoring systems for components like CPU, memory, storage, and so on. Closed-box monitoring can still be useful for monitoring at the infrastructure level, but it lacks insights and context into how the application is operating. For example, to test whether a ...