Skip to content

Instantly share code, notes, and snippets.

@pkuczynski pkuczynski/status.sh
Created Oct 16, 2017

Embed
What would you like to do?
Kubectl get pods with colorful output
kubectl get pods --all-namespaces \
| awk -v GREEN='\033[01;32m' \
-v NORMAL='\033[0m' \
-v YELLOW='\033[01;33m' \
-v RED='\033[01;31m' \
--field-separator='\s' '{
if (NR > 1) {
for (n=1; n<NF; n++) {
if (n == 3) {
split($n, ready, "/")
if (ready[1] < ready[2]) {
if (ready[1] == 0) {
COL3 = RED
} else {
COL3 = YELLOW
}
} else {
COL3 = GREEN
}
}
if (n == 4) {
if ($n ~ /^Pending/) COL4 = YELLOW
else if ($n ~ /^(Error|Crash)/) COL4 = RED
else COL4 = COL3
}
}
}
printf "%0-20s%-45s"COL3"%-8s"COL4"%-12s"NORMAL"%4.4s %8s\n", $1, $2, $3, $4, $5, $6
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.