Skip to content
LF Cert Trainer

Lesson 139 · Section 12: Troubleshooting

Lesson 139: Application failure: follow the request from the user to the broken part

Find why an application does not work: walk the path of a request (Service, selector, endpoints, readiness, target port, container, dependencies) and read each stuck Pod state to the line that fixes it. · 24 min read · 3 min video

1/10Application failure
0:00 / 3:20

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why application failures need a path, not a guess

"The application does not work" is the most common exam task, and the vaguest. The fault can be in a dozen places: a Service selector with a typo, a target port that points nowhere, an image tag that does not exist, a missing ConfigMap key, a memory limit that is too small, a readiness probe on the wrong path, or a database Service that the app cannot find. Each one produces the same symptom from the outside: the request fails.

The way through is to stop thinking about the application as one thing, and follow the path one request takes through the cluster. Every hop on that path has one command that tells you whether it works.

The request path

The path of one request, and where it breaksresolvesto IPselectorready onlytargetPortcallsClientcurl web-svc:80DNS nameweb-svc.shopServiceport 80Endpointsselector matchesPodReady 1/1Containerlistens on 8080Dependencydb-svc:5432
The path of one request, and where it breaks. Check the links from left to right. The first link that is wrong is your fault; everything after it may look broken only because of it.

Parts:

  • Client (curl web-svc:80)
  • DNS name (web-svc.shop)
  • Service (port 80)
  • Endpoints (selector matches)
  • Pod (Ready 1/1)
  • Container (listens on 8080)
  • Dependency (db-svc:5432)

Connections:

  • Client to DNS name: resolves
  • DNS name to Service: to IP
  • Service to Endpoints: selector
  • Endpoints to Pod: ready only
  • Pod to Container: targetPort
  • Container to Dependency: calls
LinkWhat must be trueHow to check
DNS nameThe client uses the right name (<svc>.<namespace>) and DNS worksnslookup web-svc.shop from a test Pod
ServiceIt exists in the right namespace, with the port the client callskubectl -n shop get svc web-svc
SelectorIts selector matches the labels on the Pods (not the Deployment's name)get svc -o jsonpath='{.spec.selector}' vs get pods --show-labels
EndpointsAt least one address listedkubectl -n shop get endpoints web-svc (or get endpointslices -l kubernetes.io/service-name=web-svc)
Ready PodOnly Pods that pass their readiness probe are endpointsREADY 1/1; describe pod for probe failures
Target porttargetPort equals the port the program listens onLogs at startup, kubectl exec + netstat -tlnp or ss -tlnp if present
ContainerThe program runs and answerskubectl logs, kubectl exec ... -- wget -qO- localhost:8080
DependenciesNames, ports and credentials it uses for its database and other services are rightEnv vars, ConfigMaps, Secrets; test that Service the same way

Two shortcuts save most of the time:

  • kubectl get endpoints <svc> splits the path in half. Addresses listed: the Service side is fine, look at ports and the containers. <none>: no Pod matches the selector, or none of them is ready.
  • A request from inside the cluster proves the whole path at once:
kubectl run tmp --rm -it --restart=Never --image=busybox:1.36 -- wget -qO- -T 2 http://web-svc.shop:80

Service faults

A Service finds Pods by labels, not by namefindsno matchno matchService web-svcselector app=webEndpoints<none>Pod web-7d9-aapp=webappPod web-7d9-bapp=webapp
A Service finds Pods by labels, not by name. The Service selects app=web, but the Pod template says app=webapp. Nothing is broken on either side, yet the Service has no endpoints and every request fails.

Parts:

  • Service web-svc (selector app=web)
  • Endpoints (<none>)
  • Pod web-7d9-a (app=webapp)
  • Pod web-7d9-b (app=webapp)

Connections:

  • Service web-svc to Endpoints: finds
  • Endpoints to Pod web-7d9-a: no match
  • Endpoints to Pod web-7d9-b: no match

A Service and its Pods are linked by labels. A typo on either side breaks the link without an error anywhere: both objects are valid, the Service simply selects nothing.

kubectl -n shop describe svc web-svc | grep -E 'Selector|TargetPort|Endpoints'
kubectl -n shop get pods -l app=web          # does the selector find anything?
kubectl -n shop get pods --show-labels
Selector:          app=web
TargetPort:        8080/TCP
Endpoints:         <none>

No resources found in shop namespace.

Fix the side the task allows you to change, usually the Service:

kubectl -n shop patch svc web-svc -p '{"spec":{"selector":{"app":"webapp"}}}'
kubectl -n shop get endpoints web-svc

The ports are the second classic. Three numbers are involved, and only two of them matter:

FieldWhereMeaning
portServiceWhat clients connect to on the Service IP
targetPortServiceWhere traffic is sent on the Pod. Must match the port the program listens on. Can be a number or the name of a container port
containerPortPod specInformational. The program listens wherever it listens, whatever this says. It matters only when targetPort refers to it by name
nodePortService (NodePort)The port opened on every node, 30000-32767

Pod failure states

Where a Pod gets stuck tells you who to askscheduledpulledstartedstays upprobe okPendingscheduler, PVCImagePullBackOffimage, registryConfigErrorConfigMap, SecretCrashLoopBackOfflogs --previousRunning 0/1readiness probeRunning 1/1in the endpoints
Where a Pod gets stuck tells you who to ask. A Pod passes the scheduler, then the kubelet pulls the image and builds the container, then your program runs, then probes decide whether it gets traffic. The stage where it stops names the evidence to read.

Parts:

  • Pending (scheduler, PVC)
  • ImagePullBackOff (image, registry)
  • ConfigError (ConfigMap, Secret)
  • CrashLoopBackOff (logs --previous)
  • Running 0/1 (readiness probe)
  • Running 1/1 (in the endpoints)

Connections:

  • Pending to ImagePullBackOff: scheduled
  • ImagePullBackOff to ConfigError: pulled
  • ConfigError to CrashLoopBackOff: started
  • CrashLoopBackOff to Running 0/1: stays up
  • Running 0/1 to Running 1/1: probe ok

A Pod passes through stages in order: the scheduler places it, the kubelet pulls the image, builds the container from its config (env, volumes, Secrets), your program runs, and probes decide whether it gets traffic. Where it stops tells you who to ask:

StateStageTypical causesRead
PendingSchedulingNot enough CPU or memory requested on any node, a taint without a toleration, a nodeSelector or affinity no node matches, a PVC that is not bounddescribe pod → FailedScheduling message; get pvc
ErrImagePull, ImagePullBackOffImageTypo in the image name, a tag that does not exist, a private registry without imagePullSecretsdescribe pod events: not found, unauthorized
CreateContainerConfigErrorConfigA ConfigMap, Secret or a key in them that does not existdescribe pod: configmap "app-config" not found
ContainerCreating (long)Volumes, sandboxA volume that cannot mount, a missing Secret volume, a CNI problem on the nodedescribe pod events: FailedMount, FailedCreatePodSandBox
CrashLoopBackOffProgramBad command or args, missing env var, wrong config, cannot reach a dependency, OOMKilled, a liveness probe killing itlogs --previous, Last State and exit code
Running, 0/1ReadinessThe readiness probe fails: wrong path, wrong port, or the app is really unhealthydescribe pod: Readiness probe failed
Completed, restartingProgramThe command finishes (for example echo), and restartPolicy: Always starts it againThe command; a long-running process is needed
Under the hood · What the back-off in CrashLoopBackOff means

CrashLoopBackOff is not an error of its own. It is the kubelet waiting before the next restart: 10 seconds, then 20, 40, up to five minutes, doubling each time. During the wait the container is not running, so kubectl logs without --previous shows nothing or a half-started container. The RESTARTS column counts the attempts. After a fix, a Deployment rolls out new Pods with no back-off; a bare Pod keeps its back-off timer until it runs for ten minutes or you recreate it.

Using it

Example · ImagePullBackOff

kubectl -n shop get pods
kubectl -n shop describe pod web-6b8f9-2kzpq | grep -A6 Events:
NAME              READY   STATUS             RESTARTS
web-6b8f9-2kzpq   0/1     ImagePullBackOff   0

  Warning  Failed   12s   kubelet  Failed to pull image "nginx:1.277": ... nginx:1.277: not found
  Warning  Failed   12s   kubelet  Error: ErrImagePull
  Normal   BackOff  1s    kubelet  Back-off pulling image "nginx:1.277"

The tag does not exist. Fix it on the Deployment and watch the rollout:

kubectl -n shop set image deploy/web nginx=nginx:1.27
kubectl -n shop rollout status deploy/web

If the message says unauthorized or pull access denied instead, the image is private: create a docker-registry Secret and add it as imagePullSecrets to the Pod template (or to the ServiceAccount).

Example · CreateContainerConfigError

kubectl -n shop describe pod api-7c5d8-q2w9e | grep -iE 'error|warning'
  Warning  Failed  4s  kubelet  Error: couldn't find key DB_PASSWORD in Secret shop/db-credentials

Either the key is misspelled in the Pod template, or the Secret lacks it. Compare the two:

kubectl -n shop get secret db-credentials -o jsonpath='{.data}' ; echo
kubectl -n shop get deploy api -o yaml | grep -B2 -A4 secretKeyRef

Fix whichever side is wrong (here the Secret had DB_PASS), then the kubelet retries by itself.

Example · Running, but never Ready

kubectl -n shop get pods -l app=web
kubectl -n shop describe pod -l app=web | grep -E 'Readiness|Unhealthy'
NAME              READY   STATUS    RESTARTS
web-5c7d9-m3n8x   0/1     Running   0

    Readiness:  http-get http://:80/healthz delay=0s timeout=1s period=10s
  Warning  Unhealthy  3s (x9 over 83s)  kubelet  Readiness probe failed: Get "http://10.244.1.7:80/healthz": dial tcp 10.244.1.7:80: connect: connection refused

The probe calls port 80, but connection refused says nothing listens there. Check the port the app really uses (its logs say listening on :8080), then fix the probe's port in the Deployment:

kubectl -n shop edit deploy web      # readinessProbe.httpGet.port: 8080
kubectl -n shop get endpoints web-svc

If the probe were a liveness probe, the same mistake would cause restarts and a crash loop instead.

Example · Everything is green, the app still fails

All Pods are 1/1, the Service has endpoints, yet the web page shows an error. Follow the next hop:

kubectl -n shop logs deploy/web | tail -n 5
connecting to database mysql:3306 ...
error: dial tcp: lookup mysql on 10.96.0.10:53: no such host

The app calls mysql, but which name does the database Service really have?

kubectl -n shop get svc
kubectl -n shop get deploy web -o jsonpath='{.spec.template.spec.containers[0].env}' ; echo
NAME          TYPE        CLUSTER-IP     PORT(S)
mysql-svc     ClusterIP   10.96.144.20   3306/TCP
web-svc       NodePort    10.96.80.11    80:30080/TCP

[{"name":"DB_HOST","value":"mysql"}]

Point the app at the real name and verify end to end:

kubectl -n shop set env deploy/web DB_HOST=mysql-svc
kubectl -n shop rollout status deploy/web
kubectl run tmp --rm -it --restart=Never --image=busybox:1.36 -- wget -qO- http://web-svc.shop

The task may instead want the Service renamed. Read it carefully: the grader checks what it asked for.

Tricks

Common mistakes

  • Comparing the selector with the Deployment's name. A Service selects Pod labels. The Deployment's own name and labels do not matter.
  • Trusting containerPort. It does not open or move anything. The program listens where it listens.
  • Reading logs without --previous during a crash loop. You see the new attempt, not the one that failed.
  • Editing the Pod. Most Pod fields cannot be changed, and the ones you can are lost when the ReplicaSet replaces it. Change the Deployment.
  • Fixing the wrong namespace. Services resolve by short name only inside their own namespace. From elsewhere it is <svc>.<namespace>.
  • Raising the memory limit blindly. First confirm OOMKilled in Last State; exit code 137 can also be a liveness probe that killed a healthy but slow app.
  • Stopping at 1/1 Running. Finish with a real request through the Service, like a user would make.

Recap

  • Walk the request: name, Service, selector, endpoints, readiness, target port, container, dependencies.
  • kubectl get endpoints splits the path in two: no endpoints means selector or readiness.
  • The stage a Pod is stuck in names the evidence: events for Pending and pulls, describe for config errors, logs --previous and the exit code for crash loops, probe events for 0/1.
  • Fix the owner (Deployment), preferably with kubectl set, and verify with a request from a test Pod.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

3 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Four workloads in one namespace are stuck, each in a different way. Read each one's state, find the cause with get, describe, events and logs, and fix it without throwing away what it needs.

    Fix · Level 2 · standard · target 20 min

  • A two-tier checkout fails end to end. Follow the request from the Service to the web pods, through their proxy to the API Service, its endpoints and its readiness probe, and fix each broken link on the way.

    Fix · Level 2 · standard · target 20 min

  • kubectl top answers with an error. Trace the Metrics API from the APIService to the Service and pods behind it, repair it, then use live node and pod numbers to answer two capacity questions.

    Fix · Level 2 · standard · target 20 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.