Last active
July 26, 2017 14:32
-
-
Save leoh0/c47dca1c98f998f0d0884c3560afac54 to your computer and use it in GitHub Desktop.
select multiple pods and log into it http://showterm.io/c58f9999d3ee6db03aa81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function kl() { | |
| chkcommand() { | |
| command -v $1 >/dev/null 2>&1 || { echo >&2 "Plz install $1 first. Aborting."; return 1; } | |
| } | |
| chkcommand fzf || return 1 | |
| chkcommand tmux || return 1 | |
| chkcommand kubectl || return 1 | |
| pods=$(kubectl get pods --all-namespaces | sed '1d' | fzf -x -m -e +s --reverse --bind=left:page-up,right:page-down --no-mouse | awk '{print $1","$2}'); | |
| if [[ $pods != "" ]]; then | |
| init="true" | |
| tmuxname=k8s-ns-$(date +%s) | |
| tmux kill-session -t $tmuxname > /dev/null 2> /dev/null || true | |
| while read line ;do | |
| NS=$(echo $line | cut -d',' -f1) | |
| NAME=$(echo $line | cut -d',' -f2) | |
| connect="kubectl exec -ti $NAME -n $NS -- bash || kubectl exec -ti $NAME -n $NS -- sh " | |
| tmux new-session -d -s $tmuxname "export KUBECONFIG=${KUBECONFIG}; $connect" | |
| if [ "${init}" == "true" ]; then | |
| if (( $(tmux ls 2> /dev/null | grep "${tmuxname}" | wc -l) > 0 )) ; then | |
| init="false" | |
| fi | |
| else | |
| tmux split-window -t "${tmuxname}" "${connect}" && \ | |
| tmux select-layout -t "${tmuxname}" "tiled" | |
| fi | |
| done <<< "$pods" | |
| tmux set-window-option -t "${tmuxname}" synchronize-panes on | |
| tmux -2 a -t $tmuxname | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment