• I needed to run tail on a bunch of PODs

  • This is not really very smart and it’s very limited but it does the job in some ways

function ktail {
     if [ -z "${1}" ]; then
         echo "Usage ktail <name> [length] [ns] [container]"
         exit 1
     else
         name=${1}
     fi
     if [ -z "${2}" ]; then
         tail="--tail=10"
     else
         if [ $2 -eq 0 ]; then
             tail=""
         else
             tail="--tail=${2}"
         fi
     fi
     if [ -z "${3}" ]; then
         ns=sysdigcloud
     else
         ns=${3}
     fi
     if [ -z "${4}" ]; then
         container=""
     else
         container="-c ${4}"
     fi
     kubectl get pods -n ${ns} | grep "${name}"| awk '{print $1}'| xargs -I{} sh -c "echo; echo; echo; echo {}; kubectl logs {} -n ${ns} ${container} ${tail}"
}
  • examples:

    • show me the last 2 lines of all PODs with alb in the name in the kube-system namespace, selecting the container nginx-ingress (yes, it’s IKS on IBM Cloud!)
      ktail alb 2 kube-system nginx-ingress
    
    • show me the last 15 lines of all PODs with api in the name in the current namespace
      ktail api 15
    
  • I know, it’s got a lot of limitation, like the positional parameters but it’s just a quick fix for the time being.