Rank Kubernetes pods by total container restart count
Build a paste-ready command, then review its compatibility and effects before running it.
kubectl get pods -A -o json | jq -r '.items[] | [.metadata.namespace,.metadata.name,([.status.containerStatuses[]?.restartCount] | add // 0)] | @tsv' | sort -k3,3nr | head -<count>Complete required fields to copy the generated command.
Compatibility
Linux + macOS + WindowsVerified for Linux, macOS, Windows using bash, zsh, powershell syntax.
Operational knowledgereview due 2027-01-19
Requirementskubectlkubectl must be installed and available on PATH.Network accessThe target must be reachable from the current environment.
Version supportkubectl Current supported releasesVerified for linux, macos, windows using bash, zsh, powershell syntax; consult compatibility notes for platform-specific differences.
Expected signalspayments worker-7d8f6b9c8f-mp2kr 14Representative successful output; values vary with the selected target and system state.
Known errorskubectl: command not foundkubectl is missing or is not available on PATH.
Verifykubectl get pods -A -o json | jq -r '.items[] | [.metadata.namespace,.metadata.name,([.status.containerStatuses[]?.restartCount] | add // 0)] | @tsv' | sort -k3,3nr | head -{{count}}The output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01kubectlCommandRuns the kubectl stage of this one-liner.
02getArgumentPasses get to kubectl.
03podsArgumentPasses pods to kubectl.
04-AOptionConfigures kubectl with the -A option.
05-oOptionSelects an output file or output format for this command.
06jsonArgumentPasses json to kubectl.
07|PipelinePasses the output on the left to the command on the right.
08jqCommandRuns the jq stage of this one-liner.
09-rOptionEnables raw, recursive, or reverse mode for this command.
10'.items[] | [.metadata.namespace,.metadata.name,([.status.containerStatuses[]?.restartCount] | add // 0)] | @tsv'ArgumentPasses '.items[] | [.metadata.namespace,.metadata.name,([.status.containerStatuses[]?.restartCount] | add // 0)] | @tsv' to jq.
11|PipelinePasses the output on the left to the command on the right.
12sortCommandRuns the sort stage of this one-liner.
13-k3,3nrOptionConfigures sort with the -k3,3nr option.
14|PipelinePasses the output on the left to the command on the right.
15headCommandRuns the head stage of this one-liner.
16-<count>OptionConfigures head with the -<count> option.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
kubectl get pods -A -o json | jq -r '.items[] | [.metadata.namespace,.metadata.name,([.status.containerStatuses[]?.restartCount] | add // 0)] | @tsv' | sort -k3,3nr | head -5
Example output
payments worker-7d8f6b9c8f-mp2kr 14
observability collector-2qs8n 3
default api-6cf59bd8dc-xm9kq 0
Illustrative output — exact values vary by system and data.
Official sources