Computer Notes/Kubernetes/Kubernetes Troubleshooting Cheat Sheet

From Cramsession
Jump to navigationJump to search
✍️ Verified Author: Mflavell • Click to view professional profile & credentials

Kubernetes Troubleshooting Cheat Sheet

A rapid triage reference for debugging Kubernetes clusters, pods, networking, and AWS EKS IAM permissions. Follow the standard incident cadence: mitigate first to restore service, then deep-dive into root cause.


1. Context & First-Look Triage

Run these commands first to orient yourself and spot broken workloads across the cluster

Verify which cluster and namespace you are targeting
kubectl config current-context
kubectl config set-context --current --namespace=<ns>
Fast scan: show every pod that is NOT Running
kubectl get pods -A --field-selector=status.phase!=Running
Detailed pod view (READY, STATUS, RESTARTS, IP, NODE)
kubectl get pods -n <ns> -o wide
Check node health (NotReady, MemoryPressure, DiskPressure)
kubectl get nodes -o wide
kubectl top nodes
kubectl top pods -n <ns> --sort-by=memory


2. Inspecting Failures (Events & Logs)

Follow the standard debugging flow: get → describe → logs → events.

Read the bottom "Events" table (scheduling, image pull, probes, OOMKilled)

kubectl describe pod <pod> -n <ns>

View logs from the PREVIOUS crashed container (essential for CrashLoopBackOff)

kubectl logs <pod> -n <ns> --previous

Stream live logs or grab the last 100 lines across all replicas of an app

kubectl logs -f <pod> -n <ns> --tail=100 kubectl logs -l app=<label> -n <ns> --tail=100

Multi-container pod (specify container name)

kubectl logs <pod> -c <container> -n <ns>

Cluster-wide warning events sorted chronologically

kubectl get events -n <ns> --field-selector type=Warning --sort-by=.lastTimestamp


3. Immediate Mitigation & Rollbacks

Unblock production SLAs and isolate faulty nodes before digging into root cause.


Check deployment rollout history and undo a bad release
kubectl rollout status deployment/<name> -n <ns>
kubectl rollout undo deployment/<name> -n <ns>
Scale healthy replicas up (or scale a broken worker down to 0)
kubectl scale deployment/<name> --replicas=<count> -n <ns>
Isolate a bad node (stop new pods from scheduling on it)
kubectl cordon <node>
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data


4. Live Shell, Networking & DNS Checks

Use these when a pod or worker is timing out or failing to reach internal services or external APIs.

Shell into a running container
kubectl exec -it <pod> -n <ns> -- /bin/sh
Attach an ephemeral debug container (works on distroless images with no shell)
kubectl debug -it <pod> -n <ns> --image=busybox --target=<container>
Spin up a temporary network debug pod (dig, nslookup, curl, tcpdump)
kubectl run netdebug --rm -it --image=nicolaka/netshoot -n <ns> -- /bin/bash
Verify Service-to-Pod selector matching (if <none>, labels don't match)
kubectl get svc,endpoints -n <ns>
Test CoreDNS and external egress from inside a pod
nslookup kubernetes.default
nslookup s3.amazonaws.com
Forward a local port to test a pod/service directly
kubectl port-forward svc/<svc> 8080:80 -n <ns>


5. Scaling, Configs & AWS EKS IAM

Commands for inspecting autoscaling, configuration objects, RBAC, and the Kubernetes-to-AWS IAM boundary (IRSA / EKS Pod Identity).

Check Horizontal Pod Autoscaler (if <unknown>, pod is missing resources.requests)
kubectl get hpa -n <ns>
kubectl describe hpa <hpa-name> -n <ns>
Verify ConfigMaps, Secrets, and Storage
kubectl get cm,secret,pvc -n <ns>
Check which ServiceAccount a pod is using (for IRSA / EKS Pod Identity)
kubectl get pod <pod> -n <ns> -o jsonpath='{.spec.serviceAccountName}'
Verify the IRSA IAM role annotation on the ServiceAccount
kubectl describe sa <sa-name> -n <ns>
Check Kubernetes RBAC permissions for a ServiceAccount
kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa-name> -n <ns>

6. Quick Status-to-Command Lookup

Status You See First Command to Run What to Look For
Pending kubectl describe pod <pod> FailedScheduling, insufficient CPU/RAM, taint mismatch, or unbound PVC.
CrashLoopBackOff kubectl logs <pod> --previous App startup error, missing env var/Secret, or aggressive livenessProbe.
OOMKilled (Exit 137) kubectl describe pod <pod> Last State: Terminated (Reason: OOMKilled). Raise memory limits or reduce worker batch size.
ImagePullBackOff kubectl describe pod <pod> Bad image tag, missing imagePullSecrets, or EKS node missing ECR read permissions / NAT egress.
AccessDenied (AWS) kubectl describe sa <sa> Missing eks.amazonaws.com/role-arn annotation, OIDC trust policy mismatch, or KMS key policy block.


7. Pod Statuses (kubectl get pods)

These reflect the lifecycle phase of the pod or the state of its containers.

Pod Status What It Means Common Cause / First Check
Pending Accepted by the cluster, but not yet scheduled onto a node (or still waiting on volumes/images). Insufficient CPU/RAM, node taint/affinity mismatch, or unbound PVC. Check kubectl describe pod for FailedScheduling.
ContainerCreating Scheduled to a node; kubelet is pulling images, mounting volumes, or attaching networking. Normal briefly. If stuck, check for volume mount failures or VPC/CNI IP exhaustion.
Running Bound to a node and at least one container is running. Check the READY column (e.g., 0/1 means the container is up, but failing its readinessProbe and receiving no traffic).
CrashLoopBackOff Container starts, crashes, and Kubernetes waits with exponential backoff before restarting it again. App startup crash, missing env var/Secret, or aggressive livenessProbe. Run kubectl logs <pod> --previous.
OOMKilled (Exit 137) Container exceeded its memory limits and was killed by the Linux kernel. Memory leak or heavy workload (e.g., large file scan). Raise memory limits or reduce worker batch size.
ImagePullBackOff Kubelet cannot pull the container image from the registry. Wrong image tag, missing imagePullSecrets, or EKS node missing ECR read permissions / NAT egress.
CreateContainerConfigError Kubelet cannot assemble the container config before starting it. Referenced ConfigMap or Secret does not exist in that namespace.
Init:0/1 / Init:Error An init container has not completed or is failing, blocking the main container from starting. Inspect the init container specifically with kubectl logs <pod> -c <init-container>.
Evicted Kubelet forcibly terminated the pod to free up node resources. Usually a symptom of Node MemoryPressure or DiskPressure.
Terminating Pod is shutting down gracefully. If stuck, check for hung shutdown hooks, stuck finalizers, or an unreachable node.
Completed All containers exited cleanly with exit code 0. Normal end state for Job and CronJob pods.
Unknown Control plane lost contact with the node hosting the pod. Node crashed, lost network connectivity, or kubelet stopped running.

8. Node Conditions (kubectl get nodes / kubectl describe node)

These reflect the health of the underlying worker machine (e.g., EC2 instance) hosting your pods.

Node Condition What It Means Impact on Pods
Ready Node is healthy and kubelet is reporting normally to the control plane. Accepts new pod scheduling normally.
NotReady Node is unhealthy or kubelet stopped sending heartbeats. No new pods schedule here; after the eviction timeout (default 5 min), existing pods are rescheduled elsewhere.
MemoryPressure Available RAM on the node dropped below the eviction threshold. Kubelet blocks new BestEffort pods and starts evicting existing pods (leaving them in Evicted state).
DiskPressure Root disk, container filesystem, or inodes are critically low (often from unrotated logs or cached images). Kubelet triggers garbage collection and evicts pods to prevent the node from locking up.
PIDPressure Too many active processes are running on the node, nearing the OS process ID limit. New containers fail to start and existing workloads may be evicted.
NetworkUnavailable The node's network plugin (CNI, such as AWS VPC CNI) is not configured or healthy. Pods on the node cannot get IPs or route cluster/external traffic.
SchedulingDisabled Node was manually cordoned (kubectl cordon <node>). Existing pods keep running, but the scheduler will not place any new pods on this node.