The following is an example of the .sh
scripts I use to forward and debug pods or features.
#!/bin/bash
# to use: sh portforward_microservice_xxx.sh env-dev | env-pre | env-pro
# it accepts additional params such as no-connectors to ignore some port forwards
# no-connectors - ignores forwards to XXX
args=("$@")
echo "INFO: using namespace ${args[0]}"
# only needed if we have several clusters for each env
if [ $1 == "env-pre" ]; then
kubectl config use-context context-for-pre
elif [ $1 == "env-pro" ]; then
kubectl config use-context context-for-pro
else
# default value - always DEV
kubectl config use-context context-for-dev
fi
# add here new variables or cases to omit
no_connectors=false
for arg in "$@"; do
case $arg in
no-connectors)
no_connectors=true
shift
;;
*)
shift
;;
esac
done
if [ "$no_connectors" = false ]; then
kubectl port-forward -n ${args[0]} svc/connector1 9210:9210 &
kubectl port-forward -n ${args[0]} svc/connector2 8000:8000 &
else
echo "INFO: ignoring connectors"
fi
# common pods we always need to call
kubectl port-forward -n ${args[0]} svc/service1 5050 &
kubectl port-forward -n ${args[0]} svc/service2 5060