Sort pods by restart count

Shows the pods that restart most often, to catch crashloops fast

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

tool
kubectl73 commands
tags
kubectltroubleshootingdebugmonitoring

More kubectl commands

  • 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}'

    Shows the reserved overhead on each node; the gap is kube and 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>"}}}]'

    Builds a ConfigMap from a KEY=VALUE file, then adds it to the container envFrom with a JSON patch

  • kubectl get pods -A -o wide

    Shows every pod with its node and IP address

  • kubectl describe pod <name> -n <ns>

    Shows events, conditions and volume mounts; the first stop when a pod is unhappy

  • kubectl logs -f <pod> -n <ns>

    Streams logs in real time; for a pod with several containers add -c <container>

all 73 kubectl commands