Last active
December 6, 2019 10:54
-
-
Save anxolin/3a8f83de7acf96e7c8d0c3dd94c25838 to your computer and use it in GitHub Desktop.
Get Kubernetes exposed service IP/Port and run bussy box
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 sh | |
SERVICE=${1:-web} | |
echo "Getting service IP and PORT for Service '$SERVICE'..." | |
# Get IP / Port | |
SERVICE_IP=$(kubectl get service $SERVICE -o go-template='{{.spec.clusterIP}}') | |
SERVICE_PORT=$(kubectl get service $SERVICE -o go-template='{{(index .spec.ports 0).port}}') | |
if [[ ! -z $SERVICE_IP && ! -z $SERVICE_PORT ]]; then | |
echo "Service '$SERVICE' is exposed in $SERVICE_IP:$SERVICE_PORT" | |
# Run bussy box | |
echo "Running bussy box..." | |
kubectl run busybox \ | |
--generator=run-pod/v1 \ | |
--image=busybox \ | |
--restart=Never \ | |
--tty \ | |
-i \ | |
--env "SERVICE_IP=$SERVICE_IP" \ | |
--env "SERVICE_PORT=$SERVICE_PORT" | |
exit 0 | |
else | |
echo "No IP/Port was assigned to '$SERVICE'. Check services:" | |
echo "\tkubectl get services" | |
echo "\tkubectl get service $SERVICE" | |
echo "\tkubectl describe service $SERVICE" | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment