Quickstart: Edit a Game Server
This guide addresses Google Kubernetes Engine and Minikube. We would welcome a Pull Request to expand this to include other platforms as well.
Prerequisites
To install on GKE, follow the install instructions (if you haven’t already) at Setting up a Google Kubernetes Engine (GKE) cluster. Also complete the “Enabling creation of RBAC resources” and “Installing Agones” sets of instructions on the same page.
To install locally on Minikube, read Setting up a Minikube cluster. Also complete the “Enabling creation of RBAC resources” and “Installing Agones” sets of instructions on the same page.
Modify the code and push another new image
Modify the simple-game-server example source code
Modify the main.go file. For example:
Change the following line in function udpReadWriteLoop
in file main.go
:
From:
response = "ACK: " + response + "\n"
To:
response = "ACK Echo Says: " + response + "\n"
Build Server
Since Docker image is using Alpine Linux, the “go build” command has to include few more environment variables.
go get agones.dev/agones/pkg/sdk
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o bin/server -a -v main.go
Using Docker File
Create a new docker image and push the image to GCP Registry
make WITH_WINDOWS=0 WITH_ARM64=0 REPOSITORY={$REGISTRY} push
Note: Review Authentication Methods for additional information regarding use of gcloud as a Docker credential helper and advanced authentication methods to the Google Container Registry.
If using Minikube, load the image into Minikube
minikube cache add gcr.io/[PROJECT_ID]/agones-agones-simple-game-server:modified
Modify gameserver.yaml
Modify the following line from gameserver.yaml to use the new configuration.
spec:
containers:
- name: simple-game-server
image: ${REGISTRY}/simple-game-server:${TAG}
If using GKE, deploy Server to GKE
Apply the latest settings to the Kubernetes container.
gcloud config set container/cluster [CLUSTER_NAME]
gcloud container clusters get-credentials [CLUSTER_NAME]
kubectl create -f gameserver.yaml
If using Minikube, deploy the Server to Minikube
kubectl apply -f gameserver.yaml
Note
If you changed main.go
again and want to apply the changes to the new game servers, then you also need
to modify the gamerserver.yaml
file’s
imagePullPolicy
to be Always
,
or the node may use a cached copy of the image, which doesn’t have the new changes.
spec:
containers:
- name: simple-game-server
image: ${REGISTRY}/simple-game-server:${TAG}
imagePullPolicy: Always
Alternatively, you can also manually increment the version
field in the Makefile
file and change the TAG
variable accordingly.
Check the GameServer Status
kubectl describe gameserver
Verify
Let’s retrieve the IP address and the allocated port of your Game Server:
kubectl get gs -o jsonpath='{.items[0].status.address}:{.items[0].status.ports[0].port}'
You can now communicate with the Game Server :
Note
If you do not have netcat installed (i.e. you get a response ofnc: command not found
),
you can install netcat by running sudo apt install netcat
.
nc -u {IP} {PORT}
Hello World!
ACK Echo Says: Hello World!
EXIT
You can finally type EXIT
which tells the SDK to run the Shutdown command, and therefore shuts down the GameServer
.
If you run kubectl describe gameserver
again - either the GameServer will be gone completely, or it will be in Shutdown
state, on the way to being deleted.
Next Steps
If you want to perform rolling updates of modified game servers, see Quickstart Create a Game Server Fleet.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified November 28, 2024: Set externalTrafficPolicy as Local for agones-allocator (#4022) (08bc4c0)