-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lei Wang <[email protected]>
- Loading branch information
1 parent
4b00884
commit f67800b
Showing
4 changed files
with
112 additions
and
58 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
# Function to get the node port for a service | ||
get_node_port() { | ||
kubectl get service "$1" -o=jsonpath='{.spec.ports[0].nodePort}' -n "$2" | ||
} | ||
|
||
# Function to get the Kubernetes API server IP | ||
get_kubernetes_api_ip() { | ||
kubectl get endpoints kubernetes -o jsonpath='{.subsets[0].addresses[0].ip}' | ||
} | ||
|
||
# Function to clean up existing iptables rules | ||
cleanup_iptables() { | ||
echo "Killing existing socat processes..." | ||
sudo pkill socat | ||
} | ||
|
||
# Function to update iptables rules for a service | ||
update_iptables() { | ||
SERVICE_NAME="$1" | ||
SOURCE_IP="$2" | ||
SOURCE_PORT="$3" | ||
NAME_SPACE="$4" | ||
K8S_API_IP="$5" | ||
|
||
echo "Updating iptables rules for $SERVICE_NAME (Source IP: $SOURCE_IP, Port: $SOURCE_PORT)" | ||
|
||
NODE_PORT=$(get_node_port "$SERVICE_NAME" "$NAME_SPACE") | ||
|
||
if [ -z "$NODE_PORT" ]; then | ||
echo "Error: Could not get node port for service $SERVICE_NAME" | ||
return 1 | ||
fi | ||
|
||
sudo socat TCP-LISTEN:${SOURCE_PORT},bind=${SOURCE_IP},fork TCP:${K8S_API_IP}:${NODE_PORT} & | ||
|
||
echo "Updated iptables rules for $SERVICE_NAME (Node Port: $NODE_PORT)" | ||
} | ||
|
||
# Main execution | ||
echo "Starting iptables update process..." | ||
|
||
K8S_API_IP=$(get_kubernetes_api_ip) | ||
if [ -z "$K8S_API_IP" ]; then | ||
echo "Error: Could not determine Kubernetes API server IP" | ||
exit 1 | ||
fi | ||
echo "Kubernetes API server IP: $K8S_API_IP" | ||
|
||
cleanup_iptables | ||
|
||
# Update rules for each service | ||
if ! update_iptables gart-release-coordinator-service 0.0.0.0 18080 gart "$K8S_API_IP"; then | ||
echo "Failed to update iptables for gart-release-coordinator-service" | ||
fi | ||
|
||
if ! update_iptables gart-release-gie-frontend-service 0.0.0.0 8182 gart "$K8S_API_IP"; then | ||
echo "Failed to update iptables for gart-release-gie-frontend-service" | ||
fi | ||
|
||
echo "iptables update process completed." | ||
|
||
echo "Script execution completed." |