DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Kubernetes & HelmLesson 9 of 16
Your progress · 0%
On this page
  1. Logs
  2. A field guide to failures
  3. Metrics
  4. The full picture
↖ Course roadmap
Lesson 9 · Monitoring & logging

Monitoring, logging and troubleshooting

Read what your cluster is telling you: Pod logs, events and describe, metrics from metrics-server, and a field guide to the failures you will meet, each reproduced for real.

35 min read · intermediate · hands-on

By the end of this lesson you'll be able to

0 of 5 complete
Lab status

Verified lab: logs, a real CrashLoopBackOff, ImagePullBackOff, a Pending PVC, kubectl top and the metrics API, all on the course's EKS cluster. The output shown is real.
Code walkthrough: the Prometheus, Grafana and tracing stack, covered by the Monitoring course.
Cloud lab: none needed; works on kind.

Things break, and Kubernetes is good at telling you why, if you know where to look. There are three places: logs (what the app said), describe and events (what Kubernetes did), and metrics (how much it used). This lesson uses each, then works through the failures you'll meet most, all reproduced for real.

Logs

The kubelet captures each container's stdout and stderr. kubectl logs reads them:

$ kubectl logs shop-web-55d49ccc4b-5xkmp --tail=5
10.42.0.115 GET /healthz 200
10.42.0.115 GET /healthz 200
10.42.0.115 GET /healthz 200
10.42.12.113 GET /healthz 200
10.42.0.115 GET /healthz 200
$ kubectl logs deployment/shop-web --tail=3 --timestamps
Found 3 pods, using pod/shop-web-55d49ccc4b-vrdz4
2026-11-09T06:09:23.283659765Z 10.42.28.149 GET /healthz 200
2026-11-09T06:09:23.559424501Z 10.42.12.113 GET /healthz 200
2026-11-09T06:09:28.283930705Z 10.42.28.149 GET /healthz 200
kubectl logs shop-web-55d49ccc4b-5xkmp --tail=5
  • kubectltalk to a Kubernetes cluster
  • logsshow a Pod’s output

Those requests are the readiness and liveness probes from the kubelet (10.42.0.115 and 10.42.28.149 are the node IPs) and the ALB health checks. Note that logs deployment/... reads one Pod; use -l app=shop-web --prefix for all of them. Logs on a node are rotated and deleted with the Pod, so production ships them to a central store (the Monitoring course uses Loki).

kubectl logs reads a file on one node. A collector copies the same file off the node before it is rotated or deleted.

kubectl logs reads a file on one node. A collector copies the same file off the node before it is rotated or deleted.

A field guide to failures

Each STATUS points to one place to look. The sections below reproduce the first three for real.

Each STATUS points to one place to look. The sections below reproduce the first three for real.

CrashLoopBackOff: the app keeps exiting

The broken image exits on start, the way an app does when it's missing a setting:

$ kubectl run broken --image=626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-broken
pod/broken created
$ kubectl get pod broken
NAME     READY   STATUS   RESTARTS      AGE
broken   0/1     Error    3 (35s ago)   49s
$ kubectl logs broken
config error: DATABASE_URL is not set
kubectl run broken --image=626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-broken
  • kubectltalk to a Kubernetes cluster
  • --image=626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-brokencontainer image
kubectl get pod broken
  • getlist objects
kubectl logs broken
  • logsshow a Pod’s output

The log gives the cause straight away. describe adds what Kubernetes saw:

$ kubectl describe pod broken | sed -n '/State:/,/Restart Count/p;/Events:/,$p'
    State:          Terminated
      Reason:       Error
      Exit Code:    1
    ...
    Restart Count:  3
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  62s                default-scheduler  Successfully assigned default/broken to ip-10-42-0-115.ap-south-1.compute.internal
  Normal   Pulled     61s                kubelet            spec.containers{broken}: Successfully pulled image "...shop-web:v3-broken" in ...
  Normal   Started    21s (x4 over 61s)  kubelet            spec.containers{broken}: Container started
  Warning  BackOff    20s (x4 over 59s)  kubelet            spec.containers{broken}: Back-off restarting failed container broken in pod broken_default(...)
kubectl describe pod broken | sed -n '/State:/,/Restart Count/p;/Events:/,$p'
  • kubectltalk to a Kubernetes cluster
  • describeshow details and events
  • |pipe: send output to the next command

The image pulled fine and the container started four times; each time it exited with code 1, and the kubelet waits longer between restarts (10s, 20s, 40s... up to 5 minutes). That growing wait is the "back-off". Reading the exit code: 1 is the app's own error, 137 is a kill (often OOM, lesson 7), 143 is a normal shutdown signal.

kubectl logs broken --previous reads the container that ran before the current one. In the lab it failed with unable to retrieve container logs: with a container this short-lived, the previous one was already cleaned up. If --previous is empty, the current container's log usually tells the same story.

ImagePullBackOff: the image can't be pulled

A typo in the tag:

$ kubectl create deployment typo --image=626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v9
$ kubectl get pods -l app=typo
typo-7b957fcd7c-vvmv8   0/1     ImagePullBackOff   0          46s
$ kubectl describe pod typo-7b957fcd7c-vvmv8 | sed -n '/Events:/,$p'
  Warning  Failed     24s (x2 over 51s)  kubelet            spec.containers{shop-web}: Error: ImagePullBackOff
  Warning  Failed     13s (x3 over 52s)  kubelet            spec.containers{shop-web}: Failed to pull image "...shop-web:v9": rpc error: code = NotFound desc ...
  Warning  Failed     13s (x3 over 52s)  kubelet            spec.containers{shop-web}: Error: ErrImagePull
kubectl create deployment typo --image=626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v9
  • kubectltalk to a Kubernetes cluster
  • createcreate an object
  • --image=626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v9container image
kubectl get pods -l app=typo
  • getlist objects
  • -lonly objects with this label
kubectl describe pod typo-7b957fcd7c-vvmv8 | sed -n '/Events:/,$p'
  • describeshow details and events
  • |pipe: send output to the next command

NotFound means the tag doesn't exist. Other causes look similar with different messages: a wrong registry name, or no permission to pull (on EKS, check the node role; elsewhere, the imagePullSecret).

Pending Pod: nowhere to run

From the autoscaling lesson, Pods asking for more CPU than the nodes had free:

  Warning  FailedScheduling  7s (x2 over 30s)  default-scheduler  0/2 nodes are available: 2 Insufficient cpu. preemption: 0/2 nodes are available: 2 No preemption victims found for incoming pod.

Pending means the scheduler hasn't placed the Pod. Its events always say why: not enough CPU or memory (requests, lesson 7), no node matching a selector or toleration (lesson 11), or a volume that can't be bound.

PVC stuck Pending: no storage

A claim naming a StorageClass that doesn't exist:

$ kubectl get pvc orphan
orphan   Pending                                      fast-ssd       <unset>                 14s
$ kubectl describe pvc orphan | sed -n '/Events:/,$p'
  Warning  ProvisioningFailed  3s (x3 over 19s)  persistentvolume-controller  storageclass.storage.k8s.io "fast-ssd" not found
kubectl get pvc orphan
  • kubectltalk to a Kubernetes cluster
  • getlist objects
kubectl describe pvc orphan | sed -n '/Events:/,$p'
  • describeshow details and events
  • |pipe: send output to the next command

Any Pod using this claim stays Pending too. kubectl get storageclass shows what exists (lesson 12).

The checklist

SymptomLook atUsual cause
CrashLoopBackOfflogs, logs --previous, exit codeApp error, missing config, failing liveness probe
ImagePullBackOffPod eventsWrong tag or registry, no pull permission
PendingPod eventsNot enough CPU or memory, selector or taint, unbound PVC
Running, not ReadyReadiness probe in describeApp not answering the probe path
OOMKilled, exit 137describe, topMemory limit too low or a leak
Service returns nothingget endpointslicesSelector matches no ready Pods

kubectl get events -A --sort-by=.lastTimestamp is the fastest overview of everything going wrong in a cluster.

Metrics

metrics-server (installed as an EKS add-on in lesson 3) collects CPU and memory from every kubelet:

$ kubectl top pods -l app=shop-web --containers
POD                         NAME   CPU(cores)   MEMORY(bytes)
shop-web-55d49ccc4b-5xkmp   web    1m           11Mi
shop-web-55d49ccc4b-mp85d   web    1m           11Mi
shop-web-55d49ccc4b-vrdz4   web    1m           11Mi
kubectl top pods -l app=shop-web --containers
  • kubectltalk to a Kubernetes cluster
  • -lonly objects with this label

The same data is an API (kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes), and it's what the Horizontal Pod Autoscaler reads in the next lesson. metrics-server keeps only the latest values, no history.

Top lane: built in, latest values only. Bottom lane: the history you need for dashboards and alerts.

Top lane: built in, latest values only. Bottom lane: the history you need for dashboards and alerts.

The full picture

kubectl answers "what's happening right now". For history, alerts and dashboards, clusters run the stack from the Monitoring course: Prometheus with kube-state-metrics and node-exporter (usually through the kube-prometheus-stack Helm chart), Grafana dashboards, Loki for logs, and OpenTelemetry with Jaeger or Tempo for traces of requests across services. On EKS, CloudWatch Container Insights is the managed alternative.

⌘
Mini mission

Diagnose three broken Pods

Start a Pod from the v3-broken image, a Deployment with a non-existent tag, and a PVC with a StorageClass that doesn't exist. For each, record the status, the one line from logs or events that explains it, and the fix.

Input: The shop-web images and a running clusterOutput: ~/debug.txt
Reveal one safe solution
$ kubectl run broken --image=<registry>/shop-web:v3-broken
$ kubectl create deployment typo --image=<registry>/shop-web:v9
$ kubectl apply -f orphan-pvc.yaml     # storageClassName: fast-ssd
$ sleep 45; kubectl get pods,pvc > ~/debug.txt
$ kubectl logs broken >> ~/debug.txt
$ kubectl get events --sort-by=.lastTimestamp | grep -E "Failed|ProvisioningFailed" >> ~/debug.txt
$ kubectl delete pod broken; kubectl delete deployment typo; kubectl delete pvc orphan
kubectl run broken --image=<registry>/shop-web:v3-broken
  • kubectltalk to a Kubernetes cluster
  • --image=<registry>/shop-web:v3-brokencontainer image
kubectl create deployment typo --image=<registry>/shop-web:v9
  • createcreate an object
  • --image=<registry>/shop-web:v9container image
kubectl apply -f orphan-pvc.yaml
  • applycreate or update from a file
  • -ffrom this file
sleep 45; kubectl get pods,pvc > ~/debug.txt
  • >write output to a file, replacing it
kubectl logs broken >> ~/debug.txt
  • logsshow a Pod’s output
  • >>append output to a file
kubectl get events --sort-by=.lastTimestamp | grep -E "Failed|ProvisioningFailed" >> ~/debug.txt
  • getlist objects
  • |pipe: send output to the next command
  • grepfind lines that match a pattern
kubectl delete pod broken; kubectl delete deployment typo; kubectl delete pvc orphan
  • deletedelete an object

Expect CrashLoopBackOff or Error with "DATABASE_URL is not set", ImagePullBackOff with NotFound, and a Pending PVC with "fast-ssd not found".

Try it yourself

0 of 5 steps done

Run each task in your own account or terminal, then tick it off.

Knowledge check

Quick check

Question 1 of 3

A Pod is in CrashLoopBackOff. What's the first thing to look at?

Go deeper

Official reading for this lesson

  • DocsDebug running PodsKubernetes ↗
  • DocsDebug PodsKubernetes ↗
  • DocsLogging architectureKubernetes ↗
  • DocsResource metrics pipelineKubernetes ↗

Or get every quiz answer right and it completes itself.

Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.

← PreviousSecurity: RBAC, network policies, Pod SecurityNext lesson →Autoscaling: Pods and nodes