Rank Kubernetes pods by memory consumption
Build a paste-ready command, then review its compatibility and effects before running it.
kubectl top pods -A --no-headers | sort -k4 -hr | head -<count>Complete required fields to copy the generated command.
Compatibility
Linux + macOSVerified for Linux, macOS using bash, zsh 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 using bash, zsh syntax; consult compatibility notes for platform-specific differences.
Expected signalssearch opensearch-0 780m 3840MiRepresentative 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 top pods -A --no-headers | sort -k4 -hr | 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.
02topArgumentPasses top to kubectl.
03podsArgumentPasses pods to kubectl.
04-AOptionConfigures kubectl with the -A option.
05--no-headersOptionConfigures kubectl with the --no-headers option.
06|PipelinePasses the output on the left to the command on the right.
07sortCommandRuns the sort stage of this one-liner.
08-k4OptionConfigures sort with the -k4 option.
09-hrOptionConfigures sort with the -hr option.
10|PipelinePasses the output on the left to the command on the right.
11headCommandRuns the head stage of this one-liner.
12-<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 top pods -A --no-headers | sort -k4 -hr | head -5
Example output
search opensearch-0 780m 3840Mi
payments worker-7d8f6b9c8f-mp2kr 240m 1210Mi
Illustrative output — exact values vary by system and data.
Official sources