forked from MetaState-Prototype-Project/prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward-local-net.sh
More file actions
executable file
·29 lines (24 loc) · 1002 Bytes
/
forward-local-net.sh
File metadata and controls
executable file
·29 lines (24 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Find Minikube IP
MINIKUBE_IP=$(minikube ip)
# Find all NodePort services with their ports
echo "[INFO] Fetching all NodePort services..."
NODEPORTS=$(kubectl get svc --all-namespaces \
-o jsonpath='{range .items[?(@.spec.type=="NodePort")]}{.metadata.namespace} {.metadata.name} {.spec.ports[*].nodePort}{"\n"}{end}')
# Loop through services and ports
while read -r line; do
NAMESPACE=$(echo "$line" | awk '{print $1}')
NAME=$(echo "$line" | awk '{print $2}')
PORTS=$(echo "$line" | cut -d' ' -f3-)
for PORT in $PORTS; do
echo "[FORWARDING] $NAMESPACE/$NAME on port $PORT"
# Check if socat already listening
if lsof -i TCP:$PORT >/dev/null; then
echo " [SKIP] Port $PORT already in use locally"
else
# Run socat in background
socat TCP4-LISTEN:$PORT,fork TCP4:$MINIKUBE_IP:$PORT &
echo " [OK] Forwarded port $PORT from Minikube to local"
fi
done
done <<<"$NODEPORTS"