Skip to content

Instantly share code, notes, and snippets.

@zackijack
Created December 10, 2020 10:12
Show Gist options
  • Save zackijack/eb5ef5eea1fe28d26ded991e1888ccf2 to your computer and use it in GitHub Desktop.
Save zackijack/eb5ef5eea1fe28d26ded991e1888ccf2 to your computer and use it in GitHub Desktop.
kubectl + jq
# Getting the list of nodes and their memory size
kubectl get nodes -o json | \
jq -r '.items | sort_by(.status.capacity.memory)[] | [.metadata.name,.status.capacity.memory] | @tsv'
# Getting the list of nodes and the number of pods running on them
kubectl get pods -o json --all-namespaces | \
jq '.items | group_by(.spec.nodeName) | map({"nodeName": .[0].spec.nodeName, "count": length}) | sort_by(.count)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment