dotfiles/home/.bin/kube-restarting

39 lines
952 B
Bash
Executable File

#!/usr/bin/env bash
source .utils
NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)"
set -e
NAMESPACE=${NAMESPACE:-default}
NAMESPACE="-A"
print_usage() {
blue "kube-restarting - Show all pods with restarts"
echo " "
underline "Usage:"
echo "kube-restarting [options]"
echo " "
underline "Options:"
echo "-h, --help show this help text"
echo "-n, --namespace the namespace the to search in (searches all if not set)"
}
while test $# -gt 0; do
case "$1" in
-n|--namespace)
shift
NAMESPACE="-n $1"
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
break
;;
esac
done
kubectl get pod ${NAMESPACE} -o json | jq --raw-output '.items[] | select([.status.containerStatuses[].restartCount] | add > 0) | "\( .metadata.namespace)/\( .metadata.name) \t \([.status.containerStatuses[].restartCount] | add)" ' | column -t