# dry-run
bash ./local_agones_forwarder.sh --dry-run true
# apply yaml
bash ./local_agones_forwarder.sh
Last active
April 20, 2023 06:41
-
-
Save guitarrapc/5e14ae08927fe2353d78058da6d2b449 to your computer and use it in GitHub Desktop.
Workaround for https://github.com/googleforgames/agones/issues/1990. Agones on DockerDesktop k8s and host access.
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
#!/bin/bash | |
set -euo pipefail | |
# Workaround for https://github.com/googleforgames/agones/issues/1990. Agones on DockerDesktop k8s and host access. | |
# DockerDesktop ローカル k8s で、Agones の GameServer にホストWindows から接続するための LoadBalancer を作成します。 | |
# see: https://github.com/googleforgames/agones/issues/1990 - Cannot connect to a game server using Docker Desktop (with integrated K8s cluster or Minikube) #1990 | |
# required agones gameserver deployed on local kubernetes. | |
while [ $# -gt 0 ]; do | |
case $1 in | |
--namespace) _NAMESPACE=$2; shift 2; ;; | |
--dry-run) _DRY_RUN=$2; shift 2; ;; | |
*) shift ;; | |
esac | |
done | |
function create_yaml() { | |
gs="${1}" | |
name=$(echo "${gs}" | cut -d ' ' -f 1) | |
port=$(echo "${gs}" | cut -d ' ' -f 2) | |
cat <<EOF | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: ${name} | |
namespace: "${namespace}" | |
labels: | |
agones.dev/gameserver: "${name}" | |
usage: host-forward | |
spec: | |
type: LoadBalancer | |
selector: | |
agones.dev/gameserver: "${name}" | |
ports: | |
- protocol: TCP | |
port: ${port} | |
targetPort: 2237 | |
EOF | |
} | |
namespace=${_NAMESPACE:=agones-gameserver} | |
if [[ "${_DRY_RUN:=false}" == "true" ]]; then | |
kubectl_args="--dry-run=client" | |
fi | |
# get gameserver name and port | |
gameservers=$(kubectl get gs -n "${namespace}" -o jsonpath='{range .items[*]}{@.metadata.name} {@.status.ports[0].port}{"\n"}{end}') | |
if [[ "${gameservers}" == "" ]]; then | |
echo "No gameservers found." | |
exit 0 | |
fi | |
# create yaml | |
yaml=$(echo "${gameservers[@]}" | while IFS= read -r gs ; do | |
create_yaml "${gs}" | |
done) | |
# delete old service | |
svc_names=$(kubectl get svc --selector usage=host-forward -o name) | |
if [[ "${svc_names}" != "" ]]; then | |
kubectl delete ${svc_names} -n "${namespace}" ${kubectl_args:=""} | |
fi | |
# create new service | |
echo "${yaml}" | kubectl apply -f - ${kubectl_args:=""} | |
# show yaml | |
if [[ ${_DRY_RUN} == "true" ]]; then | |
# show yaml | |
echo "${yaml}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment