Skip to content

Instantly share code, notes, and snippets.

@pkuczynski
Created October 16, 2017 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkuczynski/9190af94c485df526180a9abc2442371 to your computer and use it in GitHub Desktop.
Save pkuczynski/9190af94c485df526180a9abc2442371 to your computer and use it in GitHub Desktop.
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