Computer Notes/Kubernetes/Kubernetes Troubleshooting Cheat Sheet: Difference between revisions

From Cramsession
Jump to navigationJump to search
✍️ Verified Author: Mflavell • Click to view professional profile & credentials
(Created page with "= 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'''. __TOC__ == 1. Context & First-Look Triage == Run these commands first to orient yourself and spot broken workloads across the cluster. <syntaxhighlight lang="bash"> # Verify which cluster and namespace you are...")
 
No edit summary
Line 4: Line 4:


__TOC__
__TOC__


== 1. Context & First-Look Triage ==
== 1. Context & First-Look Triage ==
Line 24: Line 26:
kubectl top pods -n <ns> --sort-by=memory
kubectl top pods -n <ns> --sort-by=memory
</syntaxhighlight>
</syntaxhighlight>


== 2. Inspecting Failures (Events & Logs) ==
== 2. Inspecting Failures (Events & Logs) ==
Line 45: Line 49:
kubectl get events -n <ns> --field-selector type=Warning --sort-by=.lastTimestamp
kubectl get events -n <ns> --field-selector type=Warning --sort-by=.lastTimestamp
</syntaxhighlight>
</syntaxhighlight>


== 3. Immediate Mitigation & Rollbacks ==
== 3. Immediate Mitigation & Rollbacks ==
Line 61: Line 67:
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
</syntaxhighlight>
</syntaxhighlight>


== 4. Live Shell, Networking & DNS Checks ==
== 4. Live Shell, Networking & DNS Checks ==
Line 85: Line 93:
kubectl port-forward svc/<svc> 8080:80 -n <ns>
kubectl port-forward svc/<svc> 8080:80 -n <ns>
</syntaxhighlight>
</syntaxhighlight>


== 5. Scaling, Configs & AWS EKS IAM ==
== 5. Scaling, Configs & AWS EKS IAM ==
Line 106: Line 116:
kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa-name> -n <ns>
kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa-name> -n <ns>
</syntaxhighlight>
</syntaxhighlight>


== 6. Quick Status-to-Command Lookup ==
== 6. Quick Status-to-Command Lookup ==

Revision as of 00:14, 2 December 2026

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.

<syntaxhighlight lang="bash">

  1. Verify which cluster and namespace you are targeting

kubectl config current-context kubectl config set-context --current --namespace=<ns>

  1. Fast scan: show every pod that is NOT Running

kubectl get pods -A --field-selector=status.phase!=Running

  1. Detailed pod view (READY, STATUS, RESTARTS, IP, NODE)

kubectl get pods -n <ns> -o wide

  1. Check node health (NotReady, MemoryPressure, DiskPressure)

kubectl get nodes -o wide kubectl top nodes kubectl top pods -n <ns> --sort-by=memory </syntaxhighlight>


2. Inspecting Failures (Events & Logs)

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

<syntaxhighlight lang="bash">

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

kubectl describe pod <pod> -n <ns>

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

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

  1. 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

  1. Multi-container pod (specify container name)

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

  1. Cluster-wide warning events sorted chronologically

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


3. Immediate Mitigation & Rollbacks

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

<syntaxhighlight lang="bash">

  1. Check deployment rollout history and undo a bad release

kubectl rollout status deployment/<name> -n <ns> kubectl rollout undo deployment/<name> -n <ns>

  1. Scale healthy replicas up (or scale a broken worker down to 0)

kubectl scale deployment/<name> --replicas=<count> -n <ns>

  1. Isolate a bad node (stop new pods from scheduling on it)

kubectl cordon <node> kubectl drain <node> --ignore-daemonsets --delete-emptydir-data </syntaxhighlight>


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.

<syntaxhighlight lang="bash">

  1. Shell into a running container

kubectl exec -it <pod> -n <ns> -- /bin/sh

  1. Attach an ephemeral debug container (works on distroless images with no shell)

kubectl debug -it <pod> -n <ns> --image=busybox --target=<container>

  1. Spin up a temporary network debug pod (dig, nslookup, curl, tcpdump)

kubectl run netdebug --rm -it --image=nicolaka/netshoot -n <ns> -- /bin/bash

  1. Verify Service-to-Pod selector matching (if <none>, labels don't match)

kubectl get svc,endpoints -n <ns>

  1. Test CoreDNS and external egress from inside a pod

nslookup kubernetes.default nslookup s3.amazonaws.com

  1. Forward a local port to test a pod/service directly

kubectl port-forward svc/<svc> 8080:80 -n <ns> </syntaxhighlight>


5. Scaling, Configs & AWS EKS IAM

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

<syntaxhighlight lang="bash">

  1. Check Horizontal Pod Autoscaler (if <unknown>, pod is missing resources.requests)

kubectl get hpa -n <ns> kubectl describe hpa <hpa-name> -n <ns>

  1. Verify ConfigMaps, Secrets, and Storage

kubectl get cm,secret,pvc -n <ns>

  1. Check which ServiceAccount a pod is using (for IRSA / EKS Pod Identity)

kubectl get pod <pod> -n <ns> -o jsonpath='{.spec.serviceAccountName}'

  1. Verify the IRSA IAM role annotation on the ServiceAccount

kubectl describe sa <sa-name> -n <ns>

  1. Check Kubernetes RBAC permissions for a ServiceAccount

kubectl auth can-i --list --as=system:serviceaccount:<ns>:<sa-name> -n <ns> </syntaxhighlight>


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.