Find all failed pods cluster-wide

List pods in Failed phase across namespaces for cleanup or investigation

kubectl get pods -A --field-selector status.phase=Failed

tool
kubectl73 commands
tags
kubectltroubleshootingdebugk8s

More kubectl commands

  • kubectl wait --for=jsonpath='{.status.loadBalancer.ingress[0].ip}' svc/<name> -n <ns> --timeout=120s

    Block in CI until a Service gets its external IP; works on any jsonpath field

  • kubectl auth can-i list secrets -n <ns> --as=<name> --as-group=system:serviceaccounts

    Test RBAC as another identity without their kubeconfig; needs impersonate verb

  • kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}{"\t"}{.metadata.name}{"\t"}{.status.containerStatuses[0].restartCount}{"\n"}{end}' | sort -k3 -rn | head

    Surface the most-restarting pods to catch crashloops fast

  • kubectl get nodes -o json | jq -r '.items[] | {node:.metadata.name, capCPU:.status.capacity.cpu, allocCPU:.status.allocatable.cpu, capMem:.status.capacity.memory, allocMem:.status.allocatable.memory}'

    Show reserved overhead per node; gap = kube/system reservations

  • kubectl create configmap <name> --from-env-file=app.env -n <ns> --dry-run=client -o yaml | kubectl apply -f -; kubectl patch deploy/<name> -n <ns> --type=json -p='[{"op":"add","path":"/spec/template/spec/containers/0/envFrom/-","value":{"configMapRef":{"name":"<name>"}}}]'

    Build a CM from KEY=VALUE file, then JSON-patch it into a container's envFrom

all 73 kubectl commands