O'Reilly logo

Kubernetes Cookbook by Michael Hausenblas, Sébastien Goasguen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, such as cluster admins, networking operations folks, or namespace-level admins, focus on infrastructure aspects. Exemplary questions might be: Are nodes healthy? Shall we add a worker node? What is the cluster-wide utilization? Are users close to their usage quotas?

  • Developer roles mainly think and act in the context of their applications, which may well be—in the age of microservices—a handful to a dozen. 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 discuss recipes around cluster-internal monitoring leveraging Kubernetes liveness and readiness probes, then focus on monitoring with Heapster 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 | more Print the logs for a container in a pod or specified resource. If the pod ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required