Deploying Xonotic using Game Servers

Stay organized with collections Save and categorize content based on your preferences.

This tutorial shows how to deploy Xonotic to a Google Kubernetes Engine (GKE) cluster by using Game Servers and Agones. This tutorial assumes that you have a basic familiarity with game servers. It also assumes basic knowledge of Kubernetes and GKE. If you need an introduction, see GKE overview.

Objectives

  • Create a GKE cluster.
  • Create cloud resources that are related to Game Servers.
  • Create a Game Servers deployment.
  • Connect the Xonotic client to the server.

Costs

This tutorial uses the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator. New Google Cloud users might be eligible for a free trial.

This estimated example uses a default e2-standard-2 typed zonal GKE cluster, which includes two nodes and one hour's usage. For more information about zonal clusters, see types of clusters.

When you finish this tutorial, you can avoid continued billing by deleting the resources you created. For more information, see Clean up.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. Enable the Game Servers API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  7. Enable the Game Servers API.

    Enable the API

  8. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

Downloading the Xonotic game client

  1. On your local machine, download Xonotic.

  2. Extract the xonotic-0.8.2.zip file to the directory where you downloaded the file.

Creating a GKE cluster

  1. In the Cloud console, enable the Kubernetes Engine API.

    Enable the API

  2. In Cloud Shell, create a cluster with two nodes in the us-central1-a zone:

    gcloud container clusters create gcgs-xonotic \
        --cluster-version=1.22 \
        --tags=game-server \
        --scopes=gke-default \
        --num-nodes=2 \
        --no-enable-autoupgrade \
        --machine-type=e2-standard-2 \
        --zone=us-central1-a
    

    In general, we recommend using a zone that is closest to your users to provide the best latency. For the purpose of this tutorial, you can use the us-central1-a zone. For more information about zones and regions, see geography and regions.

  3. Get the credentials for the GKE cluster that you created:

    gcloud container clusters get-credentials gcgs-xonotic --zone=us-central1-a
    

Installing Agones on GKE

In this section, you install Agones, an open source gaming infrastructure platform.

  1. In Cloud Shell, create the agones-system namespace:

    kubectl create namespace agones-system
    
  2. To host and run game servers on Kubernetes, install Agones on the cluster:

    kubectl apply -f https://raw.githubusercontent.com/googleforgames/agones/release-1.24.0/install/yaml/install.yaml
    
  3. To validate that Agones is running, check the status of the Pods:

    kubectl get --namespace agones-system pods
    

    Agones is running when all Pods have a Running status. The output is similar to the following:

    NAME                                 READY   STATUS    RESTARTS   AGE
    agones-allocator-6694dcc89-7r75d     1/1     Running   0          28s
    agones-allocator-6694dcc89-m7ghq     1/1     Running   0          28s
    agones-allocator-6694dcc89-qp6cm     1/1     Running   0          28s
    agones-controller-56c98db844-llzzc   1/1     Running   0          22s
    agones-ping-d9d74c5c6-8kmt6          1/1     Running   0          24s
    agones-ping-d9d74c5c6-xwn4h          1/1     Running   0          24s
    
  1. In Cloud Shell, create a realm in the same region as the GKE cluster and set the time zone for that realm:

    gcloud game servers realms create realm-xonotic \
        --time-zone US/Central \
        --location us-central1
    

    In this tutorial, you create one realm for this game. In a production environment, we recommend creating a realm for each area of the world your players are in.

  2. Register your GKE cluster with Game Servers and attach it to the realm that you created:

    gcloud game servers clusters create cluster-xonotic \
        --realm=realm-xonotic \
        --gke-cluster locations/us-central1-a/clusters/gcgs-xonotic \
        --namespace=default \
        --location us-central1 \
        --no-dry-run
    
  3. Create a Game Servers deployment, which you use to store all your server configurations, and then roll them out to your Game Servers clusters:

    gcloud game servers deployments create deployment-xonotic
    
  4. In your current directory, create a file named xonotic_fleet_configs.yaml:

    touch xonotic_fleet_configs.yaml
    
  5. Copy the following example Agones fleet manifest file into the xonotic_fleet_configs.yaml file:

    - name: fleet-spec-1
      fleetSpec:
        replicas: 2
        template:
          metadata:
            labels:
              xonotic-game-server-v1-label-key: xonotic-game-server-v1-label-1
          spec:
            ports:
            - name: default
              containerPort: 26000
            template:
              spec:
                containers:
                - name: xonotic
                  image: gcr.io/agones-images/xonotic-example:0.7
    

    This fleet specifies that two game servers are available to be allocated from.

  6. In your current directory, create a file named xonotic_scaling_configs.yaml:

    touch xonotic_scaling_configs.yaml
    
  7. Copy the following example Agones fleet autoscaler manifest file into the xonotic_scaling_configs.yaml file:

      - fleetAutoscalerSpec:
          policy:
            type: Buffer
            buffer:
              bufferSize: 1
              maxReplicas: 4
        name:
          scaling-config-1
    

    The fleet autoscaler automatically maintains a buffer of one extra server in the READY state and scales up to a maximum of four servers.

  8. Create the Game Servers configuration:

    gcloud game servers configs create config-1 \
        --deployment deployment-xonotic \
        --fleet-configs-file xonotic_fleet_configs.yaml \
        --scaling-configs-file xonotic_scaling_configs.yaml
    
  9. Update the rollout deployment:

    gcloud game servers deployments update-rollout deployment-xonotic \
        --default-config config-1 --no-dry-run
    
  10. Validate the rollout of one fleet in the default namespace:

    kubectl get fleet
    

    The output is the following:

    NAME                                SCHEDULING   DESIRED   CURRENT   ALLOCATED   READY   AGE
    fleet-deployment-xonotic-config-1   Packed       2         2         0           2       4s
    

    The output confirms that you have deployed a fleet with two Xonotic server replicas in your cluster that are ready to accept connections.

Connect the Xonotic client to the server

  1. In Cloud Shell, create a firewall rule to open the UDP ports 7000‑8000 that are required to connect to the cluster:

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

    The --target-tags parameter matches the tags that you specified when you created the GKE cluster.

  2. Get the IP address and port number for an individual game server:

    kubectl get gameserver
    

    The output is similar to the following:

    NAME                                           STATE  ADDRESS                PORT                    NODE                                         AGE
    fleet-deployment-xonotic-config-1-nndvr-5gvch  Ready  IP_ADDRESS  PORT_NUMBER  gke-gcgs-xonotic-default-pool-db3d2ee8-dlg7  11s
    fleet-deployment-xonotic-config-1-nndvr-vqwpl  Ready  IP_ADDRESS  PORT_NUMBER  gke-gcgs-xonotic-default-pool-db3d2ee8-dlg7  11s
    

    Make a note of the IP_ADDRESS and the PORT_NUMBER.

  3. On your computer, double-click Xonotic to launch the Xonotic game, and then click Multiplayer.

  4. To join a game, in the Address field, enter IP_ADDRESS:PORT_NUMBER, and then click Join. Replace IP_ADDRESS and PORT_NUMBER with the IP address and port number values that you previously noted.

    You can now play the game.

    Connect the Xonotic client to Game Servers.

Clean up

The easiest way to eliminate billing is to delete the Cloud project that you created for the tutorial. Alternatively, you can delete the individual resources.

Delete the project

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Delete the individual resources

If you want to keep the project, you can manually delete the resources that you created in this tutorial.

  1. In Cloud Shell, delete the firewall rule:

    gcloud compute firewall-rules delete gcgs-xonotic-firewall
    
  2. Clear the default rollout:

    gcloud game servers deployments update-rollout deployment-xonotic \
        --clear-default-config --no-dry-run
    
  3. Delete the Game Servers configuration:

    gcloud game servers configs delete config-1 \
        --deployment deployment-xonotic
    
  4. Delete the Game Servers deployment:

    gcloud game servers deployments delete deployment-xonotic
    
  5. Delete the Game Servers cluster:

    gcloud game servers clusters delete cluster-xonotic \
        --realm=realm-xonotic --no-dry-run --location=global
    
  6. Delete the realm:

    gcloud game servers realms delete realm-xonotic
    
  7. Disable the Game Servers API:

    gcloud services disable gameservices.googleapis.com
    
  8. Delete the GKE cluster:

    gcloud container clusters delete gcgs-xonotic --zone=us-central1-a
    

What's next