Chapter 11. Monitoring and Logging

In this chapter we focus on recipes around monitoring and logging, both on the infrastructure and on the application level. In the context of Kubernetes, different roles typically have different scopes:

Administrator roles

Administrators, such as cluster admins, networking operations folks, or namespace-level admins, focus on the cluster control plane. Example questions they might ask themselves are: Are nodes healthy? Shall we add a worker node? What is the cluster-wide utilization? Are users close to their usage quotas?

Developer roles

Developers mainly think and act in the context of the application or data plane, which may well be—in the age of microservices—a handful to a dozen pods. For example, a person in a developer role might ask: Do I have enough resources allocated to run my app? How many replicas should I scale my app to? Do I have access to the right volumes, and how full are they? Is one of my apps failing and, if so, why?

We will first cover recipes focused on cluster-internal monitoring by leveraging Kubernetes liveness and readiness probes, then focus on monitoring with the Metrics Server and Prometheus, and finally cover logging-related recipes.

11.1 Accessing the Logs of a Container

Problem

You want to access the logs of the application running inside a container that is running in a specific pod.

Solution

Use the kubectl logs command. To see the various options, check the usage, like so:

$ kubectl logs --help | ...

Get Kubernetes Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.