Observability in Kubernetes

Kubernetes Intermediate/Advanced

Chapter 7 · Observability in Kubernetes

Chapter 6's autoscaling itself depends on metrics. This chapter covers how to actually see what's happening inside a cluster — revisiting cloud1-8's metrics/logs/traces framework, now specifically at the Kubernetes layer.

Revisiting Cloud1-8's Three Pillars, for Kubernetes Specifically

Metrics, logs, traces — cloud1-8's own framework, from Cloud Platforms. This chapter covers how each pillar actually works at the Kubernetes layer, distinct from the cloud-provider-level monitoring that chapter covered.

kubectl's Own Built-In Observability — First-Line Tools

  • kubectl logs — a specific container's stdout/stderr; the --previous flag retrieves a crashed container's last logs before it restarted, genuinely important since a freshly-restarted container's live logs won't show what caused the previous crash at all.
  • kubectl describe — a resource's full state, including recent Events — often the fastest way to see why a pod is stuck: a failed scheduling reason, an image pull failure.
  • kubectl get events — a cluster-wide or namespace-scoped event stream, useful for correlating when something happened across multiple resources — directly foreshadowing Course 2's own k8s2-8 troubleshooting workflow.
--previous is easy to forget exactly when it matters most
Right after a crash, the natural instinct is to check kubectl logs immediately — but a container that already restarted is showing its NEW logs, not the ones from the crash. --previous is specifically what surfaces the actual crash-causing output.

The Limitation of Built-In Tools

Genuinely great for a single resource, right now — but they don't retain history long-term (pod logs disappear when the pod is deleted), don't aggregate across many pods/services easily, and provide no dashboards, alerting, or trend analysis. Exactly the gap dedicated observability tooling exists to fill — the same log-aggregation problem cloud1-8 already covered at the cloud-provider level, recurring here specifically inside Kubernetes.

Metrics Server — The Baseline

HPA silently does nothing without Metrics Server
A genuinely easy-to-miss prerequisite: the Metrics Server is what actually powers kubectl top nodes/kubectl top pods, and it's what HPA (Chapter 6) actually queries for CPU/memory data. Without it installed, resource-based HPA simply doesn't work at all — directly the same pattern as k8s1-9's "Ingress does nothing without a controller" — a foundational piece of infrastructure worth checking explicitly rather than assumed present.

Prometheus — The De Facto Standard for Kubernetes Metrics

Prometheus is a metrics collection and storage system that pulls (scrapes) metrics from configured targets at regular intervals, rather than applications pushing metrics to it. Applications commonly expose a /metrics HTTP endpoint in a specific text format; Prometheus scrapes it periodically. Node-level metrics exporters (like node-exporter) commonly run as DaemonSets — directly reusing k8s2-2's own DaemonSet material, one exporter instance per node, for exactly the reason that chapter explained.

Grafana — Visualizing What Prometheus Collects

Prometheus stores and queries metrics, but its own native UI is minimal. Grafana is the dashboarding/visualization layer commonly paired with it — Prometheus as the data source, Grafana as the presentation layer. Genuinely worth being clear these are two separate tools with distinct jobs, not one combined product, since that's a common point of confusion for newcomers.

Logs at Scale — Beyond kubectl logs

Since kubectl logs only shows one pod at a time and loses history once a pod is gone, real clusters typically run a log-aggregation pipeline — commonly a DaemonSet-based log-shipping agent (Fluentd/Fluent Bit, k8s2-2's own concrete DaemonSet example, now with its actual real-world purpose fully explained) collecting every node's container logs and forwarding them to a centralized store (Elasticsearch, Loki, or a cloud provider's own logging service per cloud1-8's own material), where they persist beyond any individual pod's lifetime and can be searched across the whole cluster.

This Course's Own Scope, Honestly

Matching this course's recurring convention: this chapter is deliberately an orientation to Kubernetes observability, not a deep Prometheus/Grafana course — this site's own bucket list has a separate, still-outstanding Observability course topic for that depth. This chapter's job is making sure the Kubernetes-specific pieces (Metrics Server as an HPA prerequisite, DaemonSet-based collection patterns, the built-in-vs-dedicated-tooling gap) are understood — exactly what a dedicated Prometheus/Grafana course would otherwise need to re-explain from scratch in a Kubernetes context anyway.

Hands-On Exercises

Exercise 1

A pod crashed and was automatically restarted by its restart policy (Chapter 11, Course 1). A user runs kubectl logs and sees only a few seconds of output, nothing explaining the crash. Explain what's likely happening and what command/flag would actually show the crash's cause.

📄 View solution
Exercise 2

Explain why Prometheus and Grafana are described as two separate tools with distinct jobs rather than one combined product, and what each one is actually responsible for.

📄 View solution
Exercise 3

An HPA is configured correctly with reasonable CPU thresholds, but it never scales the Deployment at all, even under heavy real load. Using this chapter's material, what's a genuinely likely root cause worth checking first, and why?

📄 View solution

Chapter 7 Quick Reference

  • kubectl logs --previous, describe, get events — the immediate, first-line built-in tools
  • Built-in tools don't retain history, aggregate across pods, or provide dashboards/alerting — the gap dedicated tooling fills
  • Metrics Server — a genuinely easy-to-miss prerequisite; HPA does nothing without it, same pattern as a controller-less Ingress
  • Prometheus — pulls/scrapes metrics from /metrics endpoints; node exporters commonly run as DaemonSets (k8s2-2)
  • Grafana — a separate visualization layer over Prometheus's data, not a combined product
  • Log aggregation (Fluentd/Fluent Bit as a DaemonSet → centralized store) solves what kubectl logs can't: history and cross-pod search
  • This chapter is an orientation, not a full observability course — a separate, deeper course remains bucket-listed
  • Next chapter: Troubleshooting Kubernetes — CrashLoopBackOff, ImagePullBackOff, and other common failure patterns