Last active
November 4, 2019 22:07
-
-
Save dobesv/3a812b05d2c6788b11cad2486214c530 to your computer and use it in GitHub Desktop.
Helper scripts to open a tunnel to a service in kubernetes and launch the browser to the given service.
This file contains 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
#!/usr/bin/env bash | |
ENVIRONMENT=$1 | |
NAMESPACE=$2 | |
SERVICE_NAME=$3 | |
DEFAULT_LOCAL_PORT=4000 | |
DEFAULT_TARGET_PORT=80 | |
case $ENVIRONMENT in | |
prod* ) | |
DEFAULT_LOCAL_PORT=4400 | |
;; | |
stag* ) | |
DEFAULT_LOCAL_PORT=4450 | |
;; | |
esac | |
case $NAMESPACE in | |
dashboard ) | |
SERVICE_NAME=kubernetes-dashboard | |
NAMESPACE=kube-system | |
;; | |
grafana ) | |
SERVICE_NAME=monitoring-grafana | |
NAMESPACE=kube-system | |
;; | |
prometheus ) | |
if [ "$SERVICE_NAME" = "" ] ; then | |
SERVICE_NAME=prometheus | |
fi | |
;; | |
alertmanager ) | |
NAMESPACE=prometheus | |
SERVICE_NAME=alertmanager | |
;; | |
kibana ) | |
SERVICE_NAME=kibana | |
NAMESPACE=elasticsearch | |
;; | |
esac | |
case $SERVICE_NAME in | |
kubernetes-dashboard|dashboard ) | |
(( DEFAULT_LOCAL_PORT=DEFAULT_LOCAL_PORT+1)) | |
;; | |
grafana|monitoring-grafana ) | |
SERVICE_NAME=monitoring-grafana | |
(( DEFAULT_LOCAL_PORT=DEFAULT_LOCAL_PORT+2 )) | |
;; | |
prometheus ) | |
SERVICE_NAME=prometheus | |
DEFAULT_TARGET_PORT=9090 | |
(( DEFAULT_LOCAL_PORT=DEFAULT_LOCAL_PORT+3 )) | |
;; | |
alertmanager|alertmanager-main ) | |
SERVICE_NAME=alertmanager-main | |
DEFAULT_TARGET_PORT=9093 | |
(( DEFAULT_LOCAL_PORT=DEFAULT_LOCAL_PORT+6 )) | |
;; | |
kibana ) | |
(( DEFAULT_LOCAL_PORT=DEFAULT_LOCAL_PORT+5 )) | |
;; | |
esac | |
LOCAL_PORT=${4:-$DEFAULT_LOCAL_PORT} | |
TARGET_PORT=${5:-$DEFAULT_TARGET_PORT} | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
k() { kubectl --context ${ENVIRONMENT} "$@" -n $NAMESPACE ; } | |
(yarn -s wait-on http-get://localhost:$LOCAL_PORT && $DIR/open.sh http://localhost:$LOCAL_PORT/) & | |
k port-forward svc/$SERVICE_NAME $LOCAL_PORT:$TARGET_PORT | |
This file contains 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
#!/usr/bin/env bash | |
# Cross-platform script for opening a browser to the given URL | |
for CMD in xdg-open open cygstart start ; do | |
if [ -x "$(command -v $CMD)" ] ; then | |
$CMD "$@" | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment