#!/bin/bash -x

if [ -z "$1" ]; then
  echo USAGE: pod-sh \<pod-name-mask\> \[\<container-name\]\>
else
  #set -x #echo on
  system=""
  if [ "$1" == "-s" ]; then
    system="-n kube-system"
    shift
  fi
  [ -n "$2" ] && CONTAINER="-c $2"
  PODS=$(kubectl get pod $system|grep $1|grep Running|cut -d' ' -f1)
  echo Matching pods:
  for pod in $PODS; do
    echo $pod
  done
  kubectl exec $system -it $CONTAINER $pod -- sh
fi



