Lesson 2 of 2 Monitoring and Troubleshooting Container Workloads

Troubleshooting AKS Workloads

This lesson explains how to read Pod status, find causes with kubectl, test connectivity inside a cluster, and query Container insights.

Learning outcomes

After completing this lesson, you will be able to:

  • Interpret common Pod statuses.
  • Choose the kubectl command that reveals a cause.
  • Describe a systematic connectivity check.
  • Identify the Container insights tables.

Reading Pod status

kubectl get pods is the first command in almost every investigation. Its STATUS, READY and RESTARTS columns identify the type of problem before any detailed digging, and each common status has a typical cause.

StatusMeaningTypical cause
PendingThe Pod has not been scheduled to a nodeInsufficient CPU or memory for the requests, node selectors or taints that no node satisfies
ErrImagePull / ImagePullBackOffThe node cannot pull the imageWrong image name or tag, or no pull permission on the registry
CreateContainerConfigErrorThe container cannot be configuredA referenced ConfigMap or Secret, or a key within it, does not exist
CrashLoopBackOffThe container starts, exits and is restarted with increasing delaysAn application error at start-up, a missing setting, or a failing liveness probe
OOMKilled (last state)The container exceeded its memory limitLimit too low for the workload, or a memory leak
Running, READY 0/1The container runs but fails its readiness probeA health endpoint that fails or a dependency that is unreachable

The RESTARTS count matters too: a Running Pod with many restarts is crashing intermittently, often because of a liveness probe that is too aggressive or memory that grows until the limit is reached.

Match the pairs

Pod statuses

Exam skills 1.2.4

Match each Pod status with its typical cause.

Log in to try this activity Interactive activities are free with an account.

Finding the cause with kubectl

Three commands supply most of the detail. kubectl describe pod NAME prints the Pod's configuration and, at the end, its events, which explain scheduling failures, image pull errors, probe failures and kills. kubectl logs NAME prints the container's output, and kubectl logs NAME --previous prints the output of the container instance that crashed, which is essential for CrashLoopBackOff because the current instance may not have logged anything yet. kubectl get events lists recent events across a namespace.

kubectl get pods -n orders -o wide
kubectl describe pod orders-api-6d9f7c9b8-x2kqp -n orders
kubectl logs orders-api-6d9f7c9b8-x2kqp -n orders --previous
kubectl get events -n orders --sort-by=.lastTimestamp
kubectl top pods -n orders

kubectl top shows current CPU and memory use from the metrics server, which helps confirm a memory limit problem. For a Deployment that does not progress, kubectl describe deployment and kubectl rollout status show whether it is waiting for readiness or failing to create Pods.

The following diagram shows the troubleshooting sequence for a Pod in CrashLoopBackOff and how to read its exit code.

Finding the cause of CrashLoopBackOff after a ConfigMap edit. kubectl describe pod shows exit code 1, so the application failed at start-up; kubectl logs --previous shows the traceback of the last container, a KeyError for the variable the edit removed. Restoring the key and running kubectl rollout restart fixes it. Exit code 137 would instead point to a memory limit.
The previous container's output holds the traceback.
Scenario questions

Which kubectl command?

Exam skills 1.2.4

Choose the command that gives the evidence you need.

Log in to try this activity Interactive activities are free with an account.

Testing connectivity inside the cluster

When Pods are healthy but requests fail, the problem is usually in how traffic reaches them or leaves them. A systematic check follows the request path.

  1. Check the Service

    kubectl get endpoints SERVICE or kubectl get endpointslices must list Pod addresses; an empty list means the selector does not match or no Pod is ready.

  2. Check DNS

    From a Pod, nslookup SERVICE.NAMESPACE.svc.cluster.local should return the Service IP; failures point to CoreDNS or a wrong name.

  3. Call the Service

    From a temporary Pod, call the Service with curl to separate Service problems from ingress problems.

  4. Check the edge

    Inspect the Ingress, the ingress controller logs and the load balancer's public IP and rules.

  5. Check policies and egress

    Network policies, network security groups and firewalls can block traffic between namespaces or to Azure services.

kubectl run netcheck -n orders --rm -it --image=busybox:1.36 -- sh
kubectl port-forward service/orders-api 8080:80 -n orders

kubectl run with --rm -it starts a temporary interactive Pod that is deleted on exit; the small busybox image includes nslookup and wget for DNS and HTTP tests. kubectl port-forward forwards a local port to a Service or Pod, which tests the application without involving ingress. kubectl exec runs a command in an existing container when its image includes the needed tools.

Put in order

Following the request path

Exam skills 1.2.4

Put the connectivity checks for an AKS service in the recommended order.

Log in to try this activity Interactive activities are free with an account.

Container insights and KQL

kubectl shows the present; for history and for alerting, AKS sends data to Azure Monitor. Container insights collects container logs into the ContainerLogV2 table, Kubernetes inventory and events into tables such as KubePodInventory and KubeEvents, and node and container performance data. Azure Monitor managed service for Prometheus collects metrics, which Azure Managed Grafana can chart.

The following query, run in the cluster's Log Analytics workspace, lists the Pods that restarted most in the last day, which is often the quickest way to find an unstable workload across a large cluster. The KQL module explains the operators.

KubePodInventory
| where TimeGenerated > ago(1d)
| summarize Restarts = max(ContainerRestartCount) by Namespace, Name
| top 10 by Restarts
Match the pairs

Container insights tables

Exam skills 1.2.4 · 4.2.2

Match each Container insights table or tool with what it holds.

Log in to try this activity Interactive activities are free with an account.
Worked example

CrashLoopBackOff after a configuration change

After a ConfigMap was edited, an API's Pods enter CrashLoopBackOff. kubectl logs shows nothing useful because each new container exits within a second. kubectl describe pod shows Back-off restarting failed container, exit code 1.

Exit code 1 with immediate exits means that the application itself failed at start-up. The output of the previous container instance contains the traceback, so the next command is kubectl logs POD --previous. In this case it shows a KeyError for an environment variable that the ConfigMap edit removed; restoring the key in the ConfigMap and restarting the Deployment with kubectl rollout restart fixes it.

Increasing the memory limit would help only for exit code 137. Deleting the Pods would create new ones with the same configuration. Pulling the image again would not change a configuration error.

Check yourself

A Pod is in CreateContainerConfigError. What should you check first?

Show answer

Whether every ConfigMap and Secret the Pod references, and every key within them, exists in the Pod's namespace. kubectl describe pod shows the missing reference in its events.

Exam Tips

Remember for the exam

  • Pending: scheduling; ImagePullBackOff: image name or pull rights; CrashLoopBackOff: the app exits.
  • kubectl describe shows events; kubectl logs --previous shows the crashed container's output.
  • An empty endpoints list means a selector mismatch or no ready Pods.
  • Container insights stores logs in ContainerLogV2 and inventory in KubePodInventory.