Troubleshooting an application from A to Z
Objective
An application has been deployed, and it does not answer. It hides one fault per layer: each fault only shows up once the previous one is fixed, as in real life. In this lab you will:
- Follow a method, from the pod scheduling up to the Service
- Read the pod status, the events and the logs, including the logs of a crashed container
- Check the Service from inside the cluster
- On OpenShift, diagnose a crash caused by the SCC, and reproduce it with
oc debug
Complete this lab in 60 minutes.
Prerequisites
- A Kubernetes cluster (kind is fine) with
kubectl, and optionally K9s (ktbx install k9s) - For the last exercise: an OpenShift cluster with
oc - The labs Deployments: rolling update, rollback and canary and OpenShift Security Context Constraints
The method
Start from the pods, and go up one layer at a time:
| Symptom | Layer | Commands |
|---|---|---|
Pending | Scheduling: resources, taints, affinity, PVC | kubectl describe pod, kubectl get events |
ErrImagePull, ImagePullBackOff | Image: name, tag, registry, pull secret | kubectl describe pod |
CreateContainerConfigError | Configuration: ConfigMap, Secret | kubectl describe pod |
CrashLoopBackOff, Error | Application: the container starts then exits | kubectl logs --previous |
Running but 0/1 ready | Readiness probe | kubectl describe pod |
| Pods ready, Service does not answer | Service: selector, ports | kubectl get endpointslices, curl from a pod |
Tip
In K9s, the same steps are keyboard shortcuts on the pods view (:pods): d describe, l logs, p previous logs, s shell, y YAML. :events lists the events of the namespace.
Setup
Deploy the application. Do not read the manifest to find the faults: diagnose them from the cluster.
The goal: kubectl exec client -- curl -sS http://web answers Hello from web-....
Note
Each fix creates a new ReplicaSet. The pods of the previous, broken ReplicaSets can stay around until the rollout completes: always look at the newest pods (kubectl get pods --sort-by=.metadata.creationTimestamp).
Exercise 1: the pods are Pending
Why are the pods not scheduled? Fix the Deployment.
Exercise 2: the image
Exercise 3: CreateContainerConfigError
Exercise 4: CrashLoopBackOff
Exercise 5: Running, but not ready
Exercise 6: the Service does not answer
The pods are ready. Call the Service from the client pod, and fix it.
Exercise 7: on OpenShift
Deploy the application on OpenShift, with the fixes of exercises 1 to 6:
The pods crash. Diagnose why, and fix the Deployment without granting a new SCC.
Going further
- Debug a running pod with an ephemeral container:
kubectl debug -it <pod> --image=busybox --target=<container>, for images without a shell - Debug a node:
kubectl debug node/<node> -it --image=busybox, oroc debug node/<node>thenchroot /hoston OpenShift - On OpenShift, collect the cluster state for the support:
oc adm must-gather