Skip to content

Instantly share code, notes, and snippets.

@dejanu
Last active August 30, 2021 15:25
Show Gist options
  • Save dejanu/5f9aed75cd8f821ef233c756eb178483 to your computer and use it in GitHub Desktop.
Save dejanu/5f9aed75cd8f821ef233c756eb178483 to your computer and use it in GitHub Desktop.
oc wrapper
#!/usr/bin/bash
## Quick check cluster node health status as cluster-admin role
oc logout 2>/dev/null
echo "Select cluster ***********"
echo " 1) First cluster:"
echo " 2) Second cluster:"
read n
# add clusters here:
case $n in
1) oc login --username=<USERNAME> --password=<PASSWORD> --insecure-skip-tls-verify --server=<ADD_CLUSTER> && oc cluster-info;;
2) oc login --username=<USERNAME> --password=<PASSWORD> --insecure-skip-tls-verify --server=<ADD_CLUSTER> && oc cluster-info;;
esac
# get node conditions: Ready=Node is healthy and ready, NotReady=container-runtime/network is experiencing issues, SchedulingDisabled=Pods cannot be scheduled for placement on the node
oc version && oc get nodes
echo -e "======================= \033[0;33mSorted Events at NODE level\e[0m================="
oc get events --sort-by='{.lastTimestamp}' --all-namespaces -o json | jq '.items[] | select(.involvedObject.kind == "Node")| .message, .reason'
#oc get events --sort-by='{.lastTimestamp}' --all-namespaces -o json | jq '.items[] | select(.involvedObject.kind == "Node")'| grep --color -
echo -e "======================= \033[0;33mUsage Stats\e[0m================="
#node usage stats: CPU, Memory and consumption
oc adm top nodes --use-protocol-buffers
#check node reason for current condition
#for i in $(oc get nodes | awk 'FNR>1 {print $1}');do echo -e "Node condition reason \033[1;4;32;41mNode $i: \e[0m";oc describe node $i| awk -v RS=':' '/Addresses/';done
for i in $(oc get nodes | awk 'FNR>1 {print $1}');do echo -e "Node condition reasons \033[1;4;32;41mNode $i: \e[0m";oc describe node $i|sed -n '/Conditions/,/Addresses/p';done
echo "Start debug pod for a node: oc debug node/<NODE_NAME>"
#echo "=======================Sorted Events at POD level================="
#oc get events --sort-by='{.lastTimestamp}' --all-namespaces -o json | jq '.items[] | select(.involvedObject.kind == "Pod")| .message'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment