Tutorial Build and Run a Simple Gameserver (Rust)
Objectives
- Run a simple gameserver
- Understand how the simple gameserver uses the Agones Rust SDK
- Build a customized version of the simple gameserver
- Run your customized simple gameserver
Prerequisites
- Docker
- Agones installed on GKE
- kubectl properly configured
- A local copy of the Agones repository
- A repository for Docker images, such as Docker Hub or GC Container Registry
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 “Installing Agones” instructions on the same page.
While not required, you may wish to review the Create a Game Server, Create a Game Server Fleet, and/or Edit a Game Server quickstarts.
1. Run the simple gameserver
First, run the pre-built version of the simple gameserver and take note of the name that was created:
kubectl create -f https://raw.githubusercontent.com/googleforgames/agones/release-1.49.0/examples/rust-simple/gameserver.yaml
GAMESERVER_NAME=$(kubectl get gs -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
The game server sets up the Agones SDK, calls sdk.ready() to inform Agones that it is ready to serve traffic,
prints a message every 10 seconds, and then calls sdk.shutdown() after a minute to indicate that the gameserver
is going to exit.
You can follow along with the lifecycle of the gameserver by running
kubectl logs ${GAMESERVER_NAME} rust-simple -f
which should produce output similar to
If everything goes as expected, the gameserver will exit automatically after about a minute.
In some cases, the gameserver goes into an unhealthy state, in which case it will be restarted indefinitely. If this happens, you can manually remove it by running
kubectl delete gs ${GAMESERVER_NAME}
2. Build a simple gameserver
Change directories to your local agones/examples/rust-simple directory. To experiment with the SDK, open up main.rs
in your favorite editor and change the interval at which the gameserver calls sdk.health() from 2 seconds to 20
seconds by modifying the line in the thread assigned to let _health to be
thread::sleep(Duration::from_secs(20));
Next build a new docker image by running
cd examples/rust-simple
REPOSITORY=<your-repository> # e.g. gcr.io/agones-images
make build-image REPOSITORY=${REPOSITORY}
The multi-stage Dockerfile will pull down all of the dependencies needed to build the image. Note that it is normal for this to take several minutes to complete.
Once the container has been built, push it to your repository
docker push ${REPOSITORY}/rust-simple-server:0.4
3. Run the customized gameserver
Now it is time to deploy your newly created gameserver container into your Agones cluster.
First, you need to edit examples/rust-simple/gameserver.yaml to point to your new image:
containers:
- name: rust-simple
image: $(REPOSITORY)/rust-simple-server:0.4
imagePullPolicy: Always
Then, deploy your gameserver
kubectl create -f gameserver.yaml
GAMESERVER_NAME=$(kubectl get gs -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
Again, follow along with the lifecycle of the gameserver by running
kubectl logs ${GAMESERVER_NAME} rust-simple -f
which should produce output similar to
with the slower healthcheck interval, the gameserver gets automatically marked an Unhealthy by Agones.
To finish, clean up the gameserver by manually removing it
kubectl delete gs ${GAMESERVER_NAME}
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 June 13, 2025: Promote FeatureRollingUpdateFix to Beta (#4205) (30237be)