Skip to content

Instantly share code, notes, and snippets.

@takakabe
Created June 4, 2020 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takakabe/04dee59a29efdce04547c3adbb144bd0 to your computer and use it in GitHub Desktop.
Save takakabe/04dee59a29efdce04547c3adbb144bd0 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -u
while getopts n: opt; do
optarg="${OPTARG}"
if [[ "${opt}" = - ]]; then
opt="-${OPTARG%%=*}"
optarg="${OPTARG/${OPTARG%%=*}/}"
optarg="${optarg#=}"
set +u
if [[ -z "${optarg}" ]] && [[ ! "${!OPTIND}" = "-*" ]]; then
optarg="${!OPTIND}"
shift
fi
set -u
fi
case "-${opt}" in
-n|--namespace)
namespace="${optarg}"
;;
--*)
echo "${0}: illegal option -- ${opt##-}" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
pods=`kubectl get pods -n ${namespace:-default} | awk '{print $1}' | grep -v 'NAME'`
for pod in ${pods}; do
echo '---'
echo ${pod}
kubectl describe pods ${pod} -n ${namespace:-default} | sed -n '/^Containers:/,$p' | grep -B 1 'Container ID:' | grep -v 'Container ID:' | grep -v "\-\-" | sed -e 's/://'
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment