14 Monitoring applications and Kubernetes with Prometheus
Monitoring is the companion to logging - your monitoring system tells you something is wrong and then you can dig into the logs to find out the detail. And like logging you want to have a centralized system to collect and visualize metrics about all your application components. There's an established approach for monitoring in Kubernetes using another CNCF project - Prometheus, which is a server application that collects and stores metrics. In this chapter you'll learn how to deploy a shared monitoring system in Kubernetes with dashboards that show the health of individual applications, and the cluster as a whole.
Prometheus runs on many platforms but it's particularly well suited to Kubernetes. You run Prometheus in a Pod which has access to the Kubernetes API server, and then Prometheus queries the API to find all the targets it needs to monitor. When you deploy new apps you don't need to make any setup changes — Prometheus discovers them automatically and starts collecting metrics. Kubernetes apps are particularly well suited to Prometheus too - you'll see in this chapter how to make good use of the sidecar pattern, so every app can provide some metrics to Prometheus, even if the application itself isn’t Prometheus-ready.