Skip to content

Commit

Permalink
extend gremlin pod expose to load-balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
shirly121 committed Dec 25, 2020
1 parent 46ab90a commit 5dc3151
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions coordinator/gscoordinator/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def _create_interactive_engine_service(self):
"GREMLIN_IMAGE": self._gie_graph_manager_image,
"ENGINE_NAMESPACE": self._namespace,
"COORDINATOR_IMAGE": self._gie_graph_manager_image,
"GREMLIN_EXPOSE": self._service_type,
}
graph_manager_builder.add_simple_envs(envs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,31 @@ function _setup_config {
sh -c "$update_cmd"
parallel_run "$update_cmd" "$pod_hosts" $ENGINE_CONTAINER
}
function _random_generator {
min=$1
range=$2
_port=$(( ((RANDOM<<15)|RANDOM) % $range + $min ))
echo ${_port}
}
function _expose_gremlin_server {
port=$1
gremlin_pod=`kubectl get pods -l "graph=pod-${object_id}" | grep -v NAME | awk '{print $1}'`
kubectl expose pod ${gremlin_pod} --name=gremlin-${object_id} --port=${port} \
--target-port=${port} --type=NodePort 1>/dev/null 2>&1
[ $? -eq 0 ] || exit 1
node_port=`kubectl describe services gremlin-${object_id} | grep "NodePort" | grep "TCP" | tr -cd "[0-9]"`
[ $? -eq 0 ] || exit 1
# EXTERNAL_IP=`kubectl describe pods -l "app=manager" | grep "Node:" | head -1 | awk -F '[ /]+' '{print $3}'`
EXTERNAL_IP=`kubectl describe pods pod-${object_id} | grep "Node:" | head -1 | awk -F '[ /]+' '{print $3}'`
echo "FRONTEND_PORT:$EXTERNAL_IP:$node_port"
if [ "$GREMLIN_EXPOSE" = "LoadBalancer" ]; then
# range [50001, 53000)
external_port=$( _random_generator 50001 3000 )
kubectl expose pod ${gremlin_pod} --name=gremlin-${object_id} --port=${external_port} \
--target-port=${port} --type=LoadBalancer 1>/dev/null 2>&1
[ $? -eq 0 ] || exit 1
EXTERNAL_IP=`kubectl describe service gremlin-${object_id} | grep "LoadBalancer Ingress" | awk -F'[ :]+' '{print $3}'`
else
kubectl expose pod ${gremlin_pod} --name=gremlin-${object_id} --port=${port} \
--target-port=${port} --type=NodePort 1>/dev/null 2>&1
[ $? -eq 0 ] || exit 1
external_port=`kubectl describe services gremlin-${object_id} | grep "NodePort" | grep "TCP" | tr -cd "[0-9]"`
[ $? -eq 0 ] || exit 1
EXTERNAL_IP=`kubectl describe pods pod-${object_id} | grep "Node:" | head -1 | awk -F '[ /]+' '{print $3}'`
fi
echo "FRONTEND_PORT:$EXTERNAL_IP:$external_port"
}
export object_id=$1
export schema_path=$2
Expand Down

0 comments on commit 5dc3151

Please sign in to comment.