Installing Agones on Google Kubernetes Engine using Terraform
Before you begin
Take the following steps to enable the Kubernetes Engine API:
- Visit the Kubernetes Engine page in the Google Cloud Platform Console.
- Create or select a project.
- Wait for the API and related services to be enabled. This can take several minutes.
- Enable billing for your project.
- If you are not an existing GCP user, you may be able to enroll for a $300 US Free Trial credit.
Choosing a shell
To complete this quickstart, we can use either Google Cloud Shell or a local shell.
Google Cloud Shell is a shell environment for managing resources hosted on Google Cloud Platform (GCP). Cloud Shell comes preinstalled with the gcloud and kubectl command-line tools. gcloud
provides the primary command-line interface for GCP, and kubectl
provides the command-line interface for running commands against Kubernetes clusters.
If you prefer using your local shell, you must install the gcloud and kubectl command-line tools in your environment.
Cloud shell
To launch Cloud Shell, perform the following steps:
- Go to Google Cloud Platform Console
- From the top-right corner of the console, click the Activate Google Cloud Shell button:
- A Cloud Shell session opens inside a frame at the bottom of the console. Use this shell to run
gcloud
andkubectl
commands. Set a compute zone in your geographical region with the following command. The compute zone will be something like
us-west1-a
. A full list can be found here.gcloud config set compute/zone [COMPUTE_ZONE]
Local shell
To install gcloud
and kubectl
, perform the following steps:
- Install the Google Cloud SDK, which includes the
gcloud
command-line tool. Initialize some default configuration by running the following command.
When asked
Do you want to configure a default Compute Region and Zone? (Y/n)?
, enterY
and choose a zone in your geographical region of choice.gcloud init
Install the
kubectl
command-line tool by running the following command:gcloud components install kubectl
Installation
An example configuration can be found here: Terraform configuration with Agones submodule .
Copy this file into a local directory where you will execute the terraform commands.
The GKE cluster created from the example configuration will contain 3 Node Pools:
"default"
node pool with"game-server"
tag, containing 4 nodes."agones-system"
node pool for Agones Controller."agones-metrics"
for monitoring and metrics collecting purpose.
Additionally, a "tiller"
service account will be created with ClusterRole.
Configurable parameters:
- project - your Google Cloud Project ID (required)
- name - the name of the GKE cluster (default is “agones-terraform-example”)
- agones_version - the version of agones to install (an empty string, which is the default, is the latest version from the Helm repository)
- machine_type - machine type for hosting game servers (default is “n1-standard-4”)
- node_count - count of game server nodes for the default node pool (default is “4”)
- zone - the name of the zone you want your cluster to be created in (default is “us-west1-c”)
- network - the name of the VPC network you want your cluster and firewall rules to be connected to (default is “default”)
- log_level - possible values: Fatal, Error, Warn, Info, Debug (default is “info”)
- feature_gates - a list of alpha and beta version features to enable. For example, “PlayerTracking=true&ContainerPortAllocation=true”
Warning
On the lines that read source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=master"
make sure to change ?ref=master
to match your targeted Agones release, as Terraform modules can change between
releases.
For example, if you are targeting release master, then you will want to have
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=release-master"
as your source.
Creating the cluster
In the directory where you created module.tf
, run:
terraform init
This will cause terraform to clone the Agones repository and use the ./install/terraform
folder as a starting point of
Agones submodule, which contains all necessary Terraform configuration files.
Next, make sure that you can authenticate using gcloud:
gcloud auth application-default login
Now you can create your GKE cluster (optionally specifying the version of Agones you want to use):
terraform apply -var project="<YOUR_GCP_ProjectID>" [-var agones_version="1.0.0"]
To verify that the cluster was created successfully, set up your kubectl credentials:
gcloud container clusters get-credentials --zone us-west1-c agones-terraform-example
Then check that you have access to the Kubernetes cluster:
kubectl get nodes
You should have 6 nodes in Ready
state.
Uninstall the Agones and delete GKE cluster
To delete all resources provisioned by Terraform:
terraform destroy -var project="<YOUR_GCP_ProjectID>"
Next Steps
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.