Skip to content

Instantly share code, notes, and snippets.

@sunsided
Last active February 14, 2024 12:45
Show Gist options
  • Save sunsided/af8a90b0700917b5f16cf6f4ebb49dcb to your computer and use it in GitHub Desktop.
Save sunsided/af8a90b0700917b5f16cf6f4ebb49dcb to your computer and use it in GitHub Desktop.
Kubernetes Pod Watching Scripts
#!/usr/bin/env bash
# See https://gist.github.com/sunsided/af8a90b0700917b5f16cf6f4ebb49dcb
set -euo pipefail
# check if stdout is a terminal...
#if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput -T ansi bold)"
dim="$(tput dim)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput -T ansi sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
#fi
kubectl get pods "$@" \
| sed -E "/Shutdown/!s/(^[a-zA-Z0-9-]+)((-[a-f0-9]{8,})?(-[a-z0-9]{5,})?)/${bold}\1${dim}\2${normal}/g" \
| sed "s/Running/${green}Running${normal}/g" \
| sed "s/Pending/${yellow}Pending${normal}/g" \
| sed "s/Terminating/${magenta}Terminating${normal}/g" \
| sed "s/Completed/${blue}Completed${normal}/g" \
| sed "s/ContainerCreating/${cyan}ContainerCreating${normal}/g" \
| sed "s/Error/${red}Error${normal}/g" \
| sed "s/CrashLoopBackOff/${red}CrashLoopBackOff${normal}/g" \
| sed -E "s/(.*?Shutdown.*)/${dim}\1${normal}/g"
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
watch --color "$SCRIPT_DIR/gp $@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment