All exams← All Certified Kubernetes Administrator (CKA) notes

Application Troubleshooting: Certified Kubernetes Administrator (CKA) revision notes

Revision notes

## Application Troubleshooting in Kubernetes

Troubleshooting applications in Kubernetes is a critical skill for a CKA. It involves systematically diagnosing issues from the pod level up to service exposure.

## Common Pod Troubleshooting Scenarios

  • Pending: A pod stuck in `Pending` state often indicates a scheduling issue. Check resource requests (CPU/memory) against available node capacity using `kubectl describe pod <pod-name>` for events like `FailedScheduling`. Also, verify node selectors, taints and tolerations, or unbound PersistentVolumeClaims (PVCs).
  • CrashLoopBackOff: This state means your container is repeatedly starting and crashing. The most common causes are application errors (e.g., incorrect configuration, missing environment variables, database connection issues), an incorrect command or args in the pod definition, or missing dependencies. Use `kubectl logs <pod-name>` to inspect application output, and `kubectl describe pod <pod-name>` for restart counts and events.
  • ImagePullBackOff: Occurs when Kubernetes cannot pull the container image. Verify the image name and tag are correct. If using a private registry, ensure imagePullSecrets are correctly configured and have valid credentials. Network connectivity issues to the registry can also cause this.
  • Running (but unhealthy): If a pod is `Running` but your application isn't working, check Liveness and Readiness probes. A failing liveness probe will cause the container to restart; a failing readiness probe will remove the pod from service endpoints. Use `kubectl describe pod` to see probe status and events.

## Essential Troubleshooting Commands

  • `kubectl describe <resource-type> <resource-name>`: Provides a wealth of information, including status, events, conditions, resource requests/limits, and associated objects. Indispensable for initial diagnosis.
  • `kubectl logs <pod-name> [-c <container-name>]`: Retrieves logs from a container, crucial for understanding application behavior and errors. Use `-f` for follow, `--previous` for logs from a previous instance.
  • `kubectl exec -it <pod-name> -- bash`: Allows you to execute commands inside a running container, enabling interactive debugging, checking file systems, or running diagnostic tools.
  • `kubectl get events`: Shows cluster-level events, which can reveal issues affecting multiple pods or nodes.
  • `kubectl top pod <pod-name>` / `kubectl top node <node-name>`: Displays resource usage (CPU/memory) for pods and nodes, helping identify resource bottlenecks.
  • `kubectl get pods -o wide`: Shows which node a pod is running on, useful for node-specific issues.

## Service and Network Troubleshooting

If pods are healthy but inaccessible, investigate Services. Use `kubectl describe service <service-name>` to check its selector and ensure it matches the labels of your target pods. Verify that the Service's targetPort matches the container port. Check `kubectl get endpoints <service-name>` to confirm that healthy pods are correctly registered as endpoints. Finally, review any NetworkPolicies that might be inadvertently blocking traffic.

Key facts

Flashcards

What is the primary command to inspect detailed pod status, events, and conditions?
`kubectl describe pod <pod-name>`
tap to reveal
A pod is in `CrashLoopBackOff` state. What are common causes?
Application errors, incorrect `command`/`args` in the pod definition, or missing configuration/dependencies.
tap to reveal
How do you access logs from a specific container within a pod?
`kubectl logs <pod-name> -c <container-name>`
tap to reveal
What does `ImagePullBackOff` indicate?
Kubernetes failed to pull the container image, often due to a wrong image name/tag, private registry authentication issues, or network problems.
tap to reveal
What is the purpose of a Liveness probe?
To determine if an application within a container is running and healthy; if it fails, the container is restarted.
tap to reveal
How can you interactively debug inside a running container?
`kubectl exec -it <pod-name> -- bash` (or `sh`)
tap to reveal
A pod is stuck in `Pending`. What are potential causes?
Insufficient resources (CPU/memory), node selectors/taints, or an unbound PersistentVolumeClaim (PVC).
tap to reveal
What command helps verify if a Service's selector is correctly matching pods and if endpoints are registered?
`kubectl describe service <service-name>` and `kubectl get endpoints <service-name>`
tap to reveal
Practice questions

Application Troubleshooting: 5 practice questions

Q1. A pod named 'webapp-7b5b' in the 'prod' namespace is in a `CrashLoopBackOff` state. What is the most direct `kubectl` command to view the logs from its *previous* failed container instance?
  • A.  kubectl describe pod webapp-7b5b -n prod
  • B.  kubectl logs webapp-7b5b -n prod --previous
  • C.  kubectl logs webapp-7b5b -n prod
  • D.  kubectl exec webapp-7b5b -n prod -- tail /var/log/app.log
Show answer & explanation
✓ Answer: B. kubectl logs webapp-7b5b -n prod --previous
The `--previous` (or `-p`) flag is used with `kubectl logs` to retrieve logs from a previous, terminated instance of a container, which is essential for debugging a `CrashLoopBackOff` error.
Q2. You run `kubectl get pods` and see a pod with the status `ImagePullBackOff`. What is the most likely cause for this status?
  • A.  The readiness probe for the container is consistently failing.
  • B.  The kubelet cannot pull the container image from the specified registry.
  • C.  The container's main process is exiting with a non-zero status code.
  • D.  The cluster does not have enough CPU or memory to schedule the pod.
Show answer & explanation
✓ Answer: B. The kubelet cannot pull the container image from the specified registry.
`ImagePullBackOff` specifically indicates a failure in fetching the container image. This could be due to an incorrect image name/tag, authentication issues, or network problems between the node and the registry.
Q3. A Service named 'api-svc' is not routing traffic to its backend pods. You've confirmed the pods are running and have the correct labels. Which command would you use to verify that the Service has correctly selected the pods and to see their IP addresses?
  • A.  kubectl get service api-svc -o yaml
  • B.  kubectl logs service/api-svc
  • C.  kubectl describe service api-svc
  • D.  kubectl get pods -l app=api
Show answer & explanation
✓ Answer: C. kubectl describe service api-svc
`kubectl describe service` is the best command as it shows the Service's selector and, crucially, the 'Endpoints' field, which lists the IP addresses of the pods it is currently targeting.
Q4. A pod is in the `Running` state and its container is active, but it is not receiving traffic from its Service. `kubectl get pod <name> -o wide` shows its `READY` status as `0/1`. What is the most probable cause?
  • A.  The pod's readiness probe is failing.
  • B.  The pod was scheduled to a node with an untolerated taint.
  • C.  The pod's liveness probe is failing, causing it to restart.
  • D.  A NetworkPolicy is blocking ingress traffic to the pod.
Show answer & explanation
✓ Answer: A. The pod's readiness probe is failing.
A failing readiness probe signals that the app is not ready for traffic. Kubernetes keeps the container running but removes the pod's IP from the Service's endpoints, resulting in a `READY` status of `0/1`.
Q5. You suspect a pod named 'worker-pod' has an internal DNS resolution issue, but its container image is minimal and lacks tools like `nslookup` or `dig`. What is the recommended `kubectl` command to launch a temporary container with networking tools in the same pod namespaces to debug?
  • A.  kubectl debug pod/worker-pod -it --image=netshoot/netshoot --share-processes
  • B.  kubectl port-forward pod/worker-pod 8080:80
  • C.  kubectl exec worker-pod -- apt-get install dnsutils -y
  • D.  kubectl run dns-debug --image=busybox --attach -- nslookup google.com
Show answer & explanation
✓ Answer: A. kubectl debug pod/worker-pod -it --image=netshoot/netshoot --share-processes
`kubectl debug pod/...` creates an ephemeral debug container. Using `--share-processes` allows it to join the target pod's network and other namespaces, enabling direct debugging with tools from another image.
Test yourself
See the Certified Kubernetes Administrator (CKA) page

More Certified Kubernetes Administrator (CKA) topics