Appearance

Your first debugging workflow

Find where a workload or Service stops working by gathering evidence in the order a request depends on it.

What you will understand

  • Use Pod status, events, and container logs for different kinds of startup failures.
  • Test a request from the caller and follow it through DNS, Service, and backend.
  • Repair a selector mismatch and verify the fix from the client.

Builds on: DNS and service exposure

Find the first part that failed

Your frontend reports that the catalog is unavailable. At first, that symptom could mean the catalog did not start, DNS could not resolve its name, or the Service has no backend. Start by finding the first failed part of the path. Write down the caller, namespace, host, and port so you can repeat the exact request after a repair.

Conditions describe whether particular states hold for an object, such as whether a Pod is ready. Events report recent activity around an object, such as a failed image pull or scheduling attempt. Container logs show messages written by the running application to standard output and error. Each answers a different question. Try the startup scene and decide which evidence to check before changing the workload.

Find where Pod startup stopped

Look for a node assignment, then container state and kubelet events. Read process logs when the container has started.

  1. Check the node assignment

    A Pending Pod without a node needs scheduling evidence. A bound Pending Pod can instead be preparing images or mounts.

  2. Inspect image or volume setup

    ImagePullBackOff means image preparation is retrying. No application process from that failed start exists to write useful application logs.

  3. Read current or previous logs

    For repeated exits, read termination reason, exit code, current logs, and previous-container logs if retained. These explain a different boundary than scheduling.

One current Pod is inspected; events and prior logs exist only while retained by the environment.

Inspect the crash loop

A Pod starts, but its app exits before becoming Ready. Follow the retries, read the previous container’s log, and fix the setting in the Deployment.

1 / 6

From KubeletTo App container

Start the app container

The image is available, so the worker starts the container. Its startup script checks for APP_CONFIG before reporting readiness.

Container process
Before
Waiting to start
After
Running the startup script
Start the app container

The image is available, so the worker starts the container. Its startup script checks for APP_CONFIG before reporting readiness.

Uses a deliberately failing startup check in the lesson exercise. The animation compresses the kubelet’s retry delays and groups the rollout’s controller actions.

If kubectl reports CrashLoopBackOff again, can you tell which configuration value is missing from that message alone?
Reveal prediction answer

The waiting reason only tells you that retries are being delayed. Read the previous container logs and termination details to find this failure’s cause.

Read the last exit code and previous logs, then compare the Pod name and readiness before and after the rollout.

Reproduce and fix the startup failure
Explore another case

Open Inspect the crash loop to follow one container from its first failed start through the retry delay. CrashLoopBackOff tells you the container is waiting for another attempt. The previous container’s log tells you why this example failed.

Investigate startup before network traffic

Use the service-demo Deployment from the previous lessons. First ask if it has any ready Pods. Use a real Pod name from the list in the remaining commands. A pending Pod can have a FailedScheduling event explaining why no node is a fit. A running container that restarts can have a useful error in the previous instance’s logs. If the image never started, look at Events because there is no application output from that attempt.

kubectl get deployment service-demo
kubectl get pods -l app=service-demo -o wide
kubectl describe pod ACTUAL_POD_NAME
kubectl logs ACTUAL_POD_NAME -c web --tail=100 --timestamps
# Useful only if that container has a previous terminated instance:
kubectl logs ACTUAL_POD_NAME -c web --previous --tail=100
kubectl get events --sort-by=.metadata.creationTimestamp

Reproduce and repair a crash loop

Use the disposable kind lab cluster and source lab-env.sh first. The example container exits with code 1 until it receives APP_CONFIG. It uses a readiness check to report when startup succeeds.

kubectl --context kind-kv-lab get namespace kv-lab >/dev/null 2>&1 || \
  kubectl --context kind-kv-lab create namespace kv-lab
kubectl --context kind-kv-lab -n kv-lab apply -f - <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: trace-startup
spec:
  replicas: 1
  selector:
    matchLabels:
      app: trace-startup
  template:
    metadata:
      labels:
        app: trace-startup
    spec:
      containers:
        - name: app
          image: busybox:1.37.0
          command:
            - sh
            - -c
            - |
              if [ -z "$APP_CONFIG" ]; then
                echo 'APP_CONFIG is required' >&2
                exit 1
              fi
              touch /tmp/startup-ready
              exec sleep 3600
          readinessProbe:
            exec:
              command: ["test", "-f", "/tmp/startup-ready"]
            periodSeconds: 2
YAML

Wait for Kubernetes to delay another restart. Compare the Pod’s displayed status with the previous container’s log. The status tells you when to look. The log names the missing setting.

kubectl --context kind-kv-lab -n kv-lab wait --for=create pod \
  -l app=trace-startup --timeout=30s
pod=$(kubectl --context kind-kv-lab -n kv-lab get pods \
  -l app=trace-startup -o jsonpath='{.items[0].metadata.name}')
kubectl --context kind-kv-lab -n kv-lab wait \
  --for='jsonpath={.status.containerStatuses[0].state.waiting.reason}=CrashLoopBackOff' \
  "pod/$pod" --timeout=90s
kubectl --context kind-kv-lab -n kv-lab get "pod/$pod"
kubectl --context kind-kv-lab -n kv-lab logs "pod/$pod" -c app --previous

Set the missing environment variable on the Deployment. That changes the Pod template, so the rollout creates a new Pod with the corrected configuration. After it becomes Ready, delete the teaching Deployment.

kubectl --context kind-kv-lab -n kv-lab set env deployment/trace-startup APP_CONFIG=ready
kubectl --context kind-kv-lab -n kv-lab rollout status deployment/trace-startup --timeout=90s
kubectl --context kind-kv-lab -n kv-lab get pods -l app=trace-startup
kubectl --context kind-kv-lab -n kv-lab delete deployment trace-startup

Follow the client request

Once a backend is running, follow the request from discovery-client. Verify the client can resolve the Service. Inspect its selector and the actual Pod labels side by side. Read the EndpointSlice addresses and readiness conditions, then check that the target port reaches the application’s listener. Finally make the original request from the client. The result tells you whether the path works as a whole.

kubectl get service service-demo -o yaml
kubectl get pods -l app=service-demo --show-labels
kubectl get endpointslices -l kubernetes.io/service-name=service-demo -o yaml
# Use the existing debug client from the prior lesson.
kubectl exec discovery-client -- nslookup service-demo
kubectl exec discovery-client -- wget -qO- http://service-demo:8080/

Fix a Service that selects no Pods

A name can resolve while an invalid selector leaves the Service with no eligible endpoints. Repeat the same request after the repair.

  1. Client PodResolve the Service and attempt HTTP
    Service addressDNS works and the request fails.
  2. Service selectorCompare with the real Pod labels
    EndpointSliceThe mismatch leaves no endpoints for the intended Pods.
  3. Lab operatorCorrect the selector
    ServiceKubernetes publishes matching ready addresses.
  4. Same client PodRepeat the HTTP request
    Ready backendThe page loads through the original Service address.
Follow the sequence

A name can resolve while an invalid selector leaves the Service with no eligible endpoints. Repeat the same request after the repair.

A normal ClusterIP Service and one same-namespace debug client are used; no external gateway is involved.

Repair the Service selector

Save the manifest as debug-mismatch.yaml and apply it alongside the working service-demo workload. There are two Services now. Make the same request to debug-mismatch:8080 from the debug client and see where the evidence differs. That Service has a DNS entry, but its selector matches none of the intended Pods. Change its selector to app: service-demo, reapply, and check the slices before rerunning the request.

apiVersion: v1
kind: Service
metadata:
  name: debug-mismatch
spec:
  selector:
    app: deliberately-unmatched # The intended Pods use app: service-demo.
  ports:
    - port: 8080
      targetPort: http

Use the Service troubleshooting lab to repeat the exercise with its own test names and cleanup steps. Write down the symptom, the observation that explained it, and the result after the fix. That record helps when a later fault produces the same symptom for a different reason.

Collect evidence from the failing caller

Events can expire and repeated failures can be grouped. Capture recent evidence while the failure is happening. A test from a different namespace or container might have different DNS search paths, policy, or networking. Try from the original caller whenever possible. After the exercise delete the deliberately broken Service and the temporary client when they are no longer needed.

Check your understanding

The catalog Pods are ready. The short Service name resolves, but the request times out. What would you check before restarting the Pods?

Compare the Service selector with the Pod labels, inspect EndpointSlice readiness and ports, and verify the application’s listener. These checks can expose a bad Service mapping while the Pods themselves remain healthy. If the mapping is correct, continue through the caller’s policy and network path.

Primary documentation

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu