Sort pods by memory usage

Show pods in all namespaces sorted by memory, to find the hungriest ones

kubectl top pods -A --sort-by=memory

tool
k8s-debug27 commands
tags
podsmonitoring

More k8s-debug commands

  • kubectl get cm <name> -n <ns> -o jsonpath='{.data}'

    Print only the data field; pipe it to python -m json.tool for readable output

  • kubectl get secret <name> -n <ns> -o jsonpath='{.data}' | python3 -c "import sys,json,base64; [print(k,'=',base64.b64decode(v).decode()) for k,v in json.load(sys.stdin).items()]"

    Print all fields of a Kubernetes Secret, decoded from base64

  • kubectl api-resources --verbs=list --namespaced -o name | xargs -I{} kubectl get {} -n <ns> --ignore-not-found

    Go through every resource type in a namespace; useful for audits

  • kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.namespace}\t{.metadata.name}\t{.status.phase}\n{end}'

    Print the namespace, name and phase of every pod with JSONPath, no jq needed

  • kubectl debug -it mypod --image=busybox --target=app

    Attach an ephemeral busybox container to a running pod; --target lets it see the app container processes

all 27 k8s-debug commands