github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/scripts/vagrant/provision/run_tunnels.sh (about) 1 #!/bin/bash 2 3 set -xe 4 5 # Use correct kubeconfig 6 # NB(bodu): Provide full path of kind binary for pure ssh scripts (user env not loaded). 7 KIND=/home/$(whoami)/bin/kind 8 export KUBECONFIG="$($KIND get kubeconfig-path --name="kind")" 9 10 forwards="grafana:3000 m3coordinator:7201 m3dbnode:9003 m3dbnode:9004" 11 12 port_forward() { 13 forward=$1 14 if [[ "$forward" == "keepalive" ]]; then 15 sleep 10 16 printf "Port forwards open" 17 while true; do 18 printf "." 19 sleep 60 20 done; 21 return 0 22 fi 23 24 app=$(echo $forward | cut -f 1 -d ":") 25 port=$(echo $forward | cut -f 2 -d ":") 26 pod=$(kubectl get pod -A -o jsonpath="{.items[?(@.metadata.labels.app == \"${app}\")].metadata.name}" | tr " " "\n" | head -n 1) 27 namespace=$(kubectl get pod -A -o jsonpath="{.items[?(@.metadata.labels.app == \"${app}\")].metadata.namespace}" | tr " " "\n" | head -n 1) 28 echo "port forwarding app $app port $port pod $pod namespace $namespace" 29 kubectl port-forward --address 0.0.0.0 -n $namespace $pod $port:$port 30 } 31 32 export -f port_forward 33 34 forwards="$forwards keepalive" 35 36 echo $forwards | tr " " "\n" | xargs -P 100 -I{} bash -c 'port_forward "{}"'