uptime 99
Published in

uptime 99

Hands-On With Agones and Google Cloud Game Servers

Agones

Installation

The first thing I notice about Agones is that it is entirely Kubernetes-native. I’m a big fan of this since I run everything in Kubernetes these days; there are installing with Helm instructions which I jump to immediately. Initial Helm installation on my GKE cluster goes smoothly, and I have a handful of custom resource definitions (CRDs) and a control plane running in the agones-system namespace within a few minutes.

▶ kubectl get deploy -n agones-system -oname deployment.extensions/agones-allocator
deployment.extensions/agones-controller deployment.extensions/agones-ping
▶ kubectl get crd -oname | grep agones fleetautoscalers.autoscaling.agones.dev
fleets.agones.dev gameserverallocationpolicies.multicluster.agones.dev gameservers.agones.dev
gameserversets.agones.dev

Create a Gameserver

I have a controller, an allocator, a ping server, and some CRDs that look like they might be useful, but what do I do now? Following along in the documentation, it looks like the next step is to create a gameserver.

spec:
ports:
- name: default
portPolicy: Dynamic
containerPort: 7654
▶ kubectl get gameserver
NAME STATE ADDRESS PORT AGE
simple-udp-4pgls Ready 35.224.97.238 7063
▶ nc -u 35.224.97.238 7063
HI
ACK: HI
EXIT
ACK: EXIT
▶ kubectl get po
NAME READY STATUS RESTARTS AGE
simple-udp-4pgls 0/2 Terminating 0 30s
▶ kubectl get gameserver
NAME STATE ADDRESS PORT
simple-udp-4pgls Shutdown 35.224.97.238 7063

A Quick Note On Networking and Cluster Creation

The first time I tried to connect the gameserver, nothing happened. In my case, it was because I didn’t follow all of the wonderful documentation in the Agones installation guides. I skipped over the cluster creation section because I figured I already knew how to create one. Turns out there’s one step in there that’s a bit different than normal. Since these gameserver pods all need to listen on a UDP port, we need to open up a set of ports on the GCP firewall. Note that the port range in this case is udp:7000–8000. This port range is controlled by the Agones control plane installation, and can be configured by a value in the Helm chart:

▶ gcloud compute firewall-rules create game-server-firewall \
--allow udp:7000-8000 \
--target-tags game-server \
--description "Firewall to allow game server udp traffic"

Agones Architecture

You might be asking yourself why this gameserver thing is important, so I’m going to take a step away from the exploration and talk about what Agones is actually doing here.

Google Cloud Game Servers (GCGS)

Now that we have a handle on the basics of how Agones is installed and gameservers are run, we can start looking at what GCGS provides on top of that. I started with the quickstart guide in their documentation. The first thing this guide has you do is create a cluster and deploy Agones to it. I had already done that, so I skipped ahead to the part where we create a GCGS Realm.

Realms

Realms in GCGS are an organizational construct. While going through this exploration I was trying to figure out the best way to organize a large group of global clusters into realms. I ended up talking to a Googler in the Agones public Slack. (There’s a #google-cloud-game-servers channel in there). I won't go too in-depth about realm organization here, but the best advice I got was this:

  • A good rule of thumb is “groups of clusters in which, from a player perspective, latency differences between them don’t matter”
▶ gcloud game servers realms create agones-blog --time-zone EST --location us-central1
Create request issued for: [agones-blog]
Waiting for operation [projects/gcp-prime/locations/us-central1/operations/operation-1598980635305-5ae43b0c52589-34a097b6-d0659fc7] to c omplete...done.
Created realm [agones-blog].
▶ gcloud game servers clusters create agones-blog --realm=agones-blog --gke-cluster locations/us-central1/clusters/agones-blog --namespace=default --location us-central1 --no-dry-run
Create request issued for: [agones-blog]
Waiting for [operation-1598980727087-5ae43b63da1ee-88b19318-22a70d4f] to finish...done.
Created game server cluster: [agones-blog]
▶ gcloud game servers deployments create agones-blog
Create request issued for: [agones-blog]
Waiting for operation [projects/gcp-prime/locations/global/operations/operation-1598980944523-5ae43c3336ffd-4eb7fce4-fd872d08] to complete...done.
Created deployment [agones-blog].
▶ gcloud game servers configs create config-1 --deployment agones-blog --fleet-configs-file fleet_configs.yaml
Create request issued for: [config-1]
Waiting for operation [projects/gcp-prime/locations/global/operations/operation-1598981023478-5ae43c7e83334-58008b9c-8df141c0] to complete...done.
Created game server config [config-1].
- name: fleet-spec-1
fleetSpec:
replicas: 2
template:
metadata:
labels:
foo: bar
spec:
ports:
- name: default
portPolicy: Dynamic
containerPort: 7654
template:
spec:
containers:
- name: simple-udp
image: gcr.io/agones-images/udp-server:0.17
▶ gcloud game servers deployments update-rollout agones-blog --default-config config-1 --no-dry-run
Update rollout request issued for: [agones-blog]
Waiting for [operation-1598981253616-5ae43d59fd30b-b841d131-f1822e0c] to finish...done.
Updated rollout for: [agones-blog]
createTime: '2020-09-01T17:22:24.587136253Z'
defaultGameServerConfig: projects/gcp-prime/locations/global/gameServerDeployments/agones-blog/configs/config-1
etag: fHXlfY2MivvPraKyPJEseJF5SqjaBfUrnaWMGT1aCb8
name: projects/gcp-prime/locations/global/gameServerDeployments/agones-blog/rollout
updateTime: '2020-09-01T17:22:25.547699385Z'
▶ kubectl get fleet
NAME SCHEDULING DESIRED CURRENT
fleet-agones-blog-config-1 Packed 2 2
▶ kubectl get gameserver
NAME STATE ADDRESS PORT
fleet-agones-blog-config-1-st55c-8gbd2 Ready 34.123.40.127 7212 fleet-agones-blog-config-1-st55c-rnxjh Ready 34.123.40.127 7839

Why Use GCGS?

Up to this point it might seem like you could just deploy the fleet to your cluster using the Agones CRD, which is entirely correct. The real power of GCGS is in the multi-cluster management of these fleets.

Gameserver Allocation

Up to this point, we’ve seen how we use Agones + GCGS to deploy gameservers to multiple clusters, but how do we actually use these gameservers? We know that each gameserver is in a Ready state, and that each gameserver can receive UDP traffic on a specified port and IP address. Now let's explore another powerful Agones concept: allocation.

In Summary

Agones is an open source platform that provides CRDs and a controller designed to run gameservers in Kubernetes. It’s straightforward to get running, and the documentation is great. Adding Google Cloud Game Servers allows you to manage multiple clusters running Agones from a central point, and makes deploying gameservers across all of the clusters much simpler.

--

--

We collect, curate, and publish articles on everything cloud, kubernetes, open source, and security.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fairwinds

Fairwinds — The Kubernetes Enablement Company | Editor of uptime 99