Quickstart

In this quickstart, you learn how to work with game server realms, clusters, deployments, configs, and rollouts in Game Servers using the gcloud command-line tool.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Cloud Console, on the project selector page, select or create a Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud project. Learn how to confirm billing is enabled for your project.

  4. Ensure that you have enabled the Game Services API.
  5. Enable Game Services API

Choosing a shell

To complete this quickstart, you can use either Cloud Shell or your local shell.

Cloud Shell is a shell environment for managing resources hosted on Google Cloud. Cloud Shell comes preinstalled with the gcloud command-line tool. The gcloud tool provides the primary command-line interface for Game Servers.

Cloud Shell

To launch Cloud Shell, perform the following steps:

  1. Go to Google Cloud Console.

    Google Cloud Console

  2. From the upper-right corner of the console, click the Activate Cloud Shell button:

A Cloud Shell session opens inside a frame lower on the console. You use this shell to run gcloud commands.

Local shell

To install gcloud, install the Cloud SDK, which includes the gcloud command-line tool.

Verify that you have set desired default project for gcloud command-line tool (otherwise you need to specify flag --project explicitly for each command later):

gcloud config list project

If not you can run the following command to set a default project, replacing project-id with your desired project ID :

gcloud config set project project-id

Run the following command to verify your version of the Google Cloud SDK. Game Servers requires version 306.0.0 or higher of the SDK.

gcloud version

To update your installation, run the following command:

gcloud components update

If you select local shell, then you might need to install kubectl:

gcloud components install kubectl

Creating a Google Kubernetes Engine cluster

To create a Google Kubernetes Engine cluster:

  1. Enable the Kubernetes Engine API by visiting the Google Kubernetes Engine page in the Google Cloud Console.

  2. Run the following command to create a cost-optimized cluster with one node in the us-central1-a zone:

    gcloud container clusters create gcgs-quickstart \
    --cluster-version=1.15 \
    --tags=game-server \
    --scopes=gke-default \
    --num-nodes=1 \
    --no-enable-autoupgrade \
    --machine-type=e2-standard-2 \
    --zone=us-central1-a
    
  3. Run the following command to retrieve the credentials for the GKE cluster you created in the previous step:

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

Installing Agones on GKE

In this section, you install the open source Agones gaming infrastructure platform. To install Agones:

  1. Run the following command to create the agones-system namespace:

    kubectl create namespace agones-system
    
  2. Run the following command to install Agones:

    kubectl apply -f https://raw.githubusercontent.com/googleforgames/agones/release-1.7.0/install/yaml/install.yaml
    
  3. You can validate that Agones system is running by checking the status of the Kubernetes pods:

    kubectl get --namespace agones-system pods
    

    All the pods are expected to be in a Running state:

    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
    

Creating Game Servers resources

To create Game Servers resources:

  1. Create a realm in the same location as the GKE cluster:

    gcloud game servers realms create realm-quickstart --time-zone EST --location us-central1
    
  2. Register your Agones GKE cluster with Game Servers and attach it to the realm you created in the previous step:

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

    gcloud game servers deployments create deployment-quickstart
    

    Now that you have a game server deployment, you can add a game server config to it using the gcloud tool.

  4. Copy the following example Agones fleet spec manifest to a new file named fleet_configs.yaml in the current directory:

    - 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
    
  5. To create the game server config, run the following command:

    gcloud game servers configs create config-1 --deployment deployment-quickstart --fleet-configs-file fleet_configs.yaml
    
  6. To update the rollout, run the following command:

    gcloud game servers deployments update-rollout deployment-quickstart --default-config config-1 --no-dry-run
    
  7. To validate the rollout of one fleet under default namespace, run the following command:

    kubectl get fleet
    

    The following illustrates the expected output:

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

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

Testing connectivity to the UDP server

To test connectivity to the UDP server:

  1. Create a firewall rule to open the UDP ports required to connect to the cluster:

    gcloud compute firewall-rules create gcgs-quickstart-firewall \
    --allow udp:7000-8000 \
    --target-tags game-server \
    --description "Firewall to allow game server udp traffic"
    
  2. Next, get the IP address and port number for an individual game server:

    kubectl get gameserver
    

    The command returns output similar to the following:

    NAME                                                 STATE   ADDRESS          PORT   NODE                                             AGE
    fleet-deployment-quickstart-config-1-nndvr-5gvch   Ready   IP_address   port_number   gke-gcgs-quickstart-default-pool-db3d2ee8-dlg7   11s
    fleet-deployment-quickstart-config-1-nndvr-vqwpl   Ready   IP_address   port_number   gke-gcgs-quickstart-default-pool-db3d2ee8-dlg7   11s
    
  3. To test connectivity, you run the Netcat command. To install Netcat on Linux, run the following command:

    sudo apt install netcat
    
  4. To start the test, run the following command:

    nc -u IP_address port_number
    
  5. Next, type Hello and the command returns output similar to the following:

    Hello
    > ACK: Hello
    

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

If you don't want to keep any of the resources you created in this quickstart, you can delete the project:

  1. In the Cloud Console, go to the Manage resources page.

    Go to the Manage resources page

  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.

Alternatively, if you want to keep the project, complete the following steps to manually delete the resources you created in this quickstart:

  1. To delete the firewall rule, run the following command:

    gcloud compute firewall-rules delete gcgs-quickstart-firewall
    
  2. To clear the default rollout, run the following command:

    gcloud game servers deployments update-rollout deployment-quickstart --clear-default-config --no-dry-run
    
  3. To delete the game server config, run the following command:

    gcloud game servers configs delete config-1 --deployment deployment-quickstart
    
  4. To delete the game server deployment, run the following command:

    gcloud game servers deployments delete deployment-quickstart
    
  5. To delete the game server cluster, run the following command:

    gcloud game servers clusters delete cluster-quickstart --realm=realm-quickstart --location=us-central1 --no-dry-run
    
  6. To delete the realm, run the following command:

    gcloud game servers realms delete realm-quickstart --location=us-central1
    
  7. To disable the Game Services API, run the following command:

    gcloud services disable gameservices.googleapis.com
    
  8. To delete the GKE cluster, run the following command:

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

What's next

For a technical introduction to Game Servers concepts, see the Overview of Game Servers.

Learn about specific Game Servers tasks in the How-to guides.

Review the Terraform deployment sample.