Skip to content

Instantly share code, notes, and snippets.

@WadeBarnes
Last active October 17, 2023 13:40
Show Gist options
  • Save WadeBarnes/ebb9e19428f0abd3dc2357cce1ac6241 to your computer and use it in GitHub Desktop.
Save WadeBarnes/ebb9e19428f0abd3dc2357cce1ac6241 to your computer and use it in GitHub Desktop.
OpenShift - Rough script to find out where (which node) all your pods are running (this can take some time to run if you have access to lots of namespaces).
# Examples:
#
# - List all pods in an 'Unknown' state:
# oc projects -q | xargs -I {} sh -c "oc get -n {} pod -o wide 2>/dev/null | grep Unknown | awk '{print \"{},\"\$1\",\"\$3\",\"\$7}' | column -t -s , -N Namespace,Pod,Status,Node"
#
# - Delete all pods in an 'Unknown' state:
# oc projects -q | xargs -I {} sh -c "oc get -n {} pod -o wide 2>/dev/null | grep Unknown | \$(awk '{print \"oc -n {} delete --force --grace-period=0 pod \" \$1}')"
#
# - List pods on a given node:
# oc projects -q | xargs -I {} sh -c 'echo -e "\n{}:" && oc get -n {} pod -o wide 2>/dev/null | grep Running | grep ociopf-p-195.dmz' | awk '{print $1","$7}' | column -t -s ,
#
# - List pods more than one node using RegEx:
# oc projects -q | xargs -I {} sh -c 'echo -e "\n{}:" && oc get -n {} pod -o wide 2>/dev/null | grep Running | grep -E ociopf-p-\(195\|196\|182\|197\|198\|185\|186\|181\).dmz' | awk '{print $1","$7}' | column -t -s ,
#
# - List all with Status:
# oc projects -q | xargs -I {} sh -c 'echo -e "\n{}:" && oc get -n {} pod -o wide 2>/dev/null' | awk '{print $1","$3","$7}' | column -t -s ,
#
# - List all non-running pods:
# oc projects -q | xargs -I {} sh -c 'echo -e "\n{}:" && oc get -n {} pod -o wide 2>/dev/null | grep -v Running | grep -v Completed' | awk '{print $1","$3","$7}' | column -t -s ,
oc projects -q | xargs -I {} sh -c 'echo -e "\n{}:" && oc get -n {} pod -o wide 2>/dev/null | grep Running' | awk '{print $1","$7}' | column -t -s ,
@itchison
Copy link

Thanks for this. I took a stab at writing it in powershell:
https://gist.github.com/itchison/19b2b69b353d91e5e2f140ae2020a389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment