1 - Installing Code Blind on Google Kubernetes Engine using Terraform
You can use Terraform to provision a GKE cluster and install Code Blind on it.
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
and kubectl
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)?
, enter Y
and choose a zone in your geographical region of choice.
- 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 Code Blind 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 Code Blind Controller."agones-metrics"
for monitoring and metrics collecting purpose.
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 “e2-standard-4”)
- node_count - count of game server nodes for the default node pool (default is “4”)
- enable_image_streaming - whether or not to enable image streaming for the
"default"
node pool (default is true) - zone - (Deprecated, use location) 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”)
- subnetwork - the name of the subnetwork in which the cluster’s instances are launched. (required when using non default network)
- 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”
- gameserver_minPort - the lower bound of the port range which gameservers will listen on (default is “7000”)
- gameserver_maxPort - the upper bound of the port range which gameservers will listen on (default is “8000”)
- gameserver_namespaces - a list of namespaces which will be used to run gameservers (default is
["default"]
). For example ["default", "xbox-gameservers", "mobile-gameservers"]
- force_update - whether or not to force the replacement/update of resource (default is true, false may be required to prevent immutability errors when updating the configuration)
- location - the name of the location you want your cluster to be created in (default is “us-west1-c”)
- autoscale - whether you want to enable autoscale for the gameserver nodepool (default is false)
- min_node_count - the minimum number of nodes for a nodepool when autoscale is enabled (default is “1”)
- max_node_count - the maximum number of nodes for a nodepool when autoscale is enabled (default is “5”)
Warning
On the lines that read source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=main"
make sure to change ?ref=main
to match your targeted Code Blind release, as Terraform modules can change between
releases.
For example, if you are targeting release-1.38.0, then you will want to have
source = "git::https://github.com/googleforgames/agones.git//install/terraform/modules/gke/?ref=release-1.38.0"
as your source.
Creating the cluster
In the directory where you created module.tf
, run:
This will cause terraform to clone the Code Blind repository and use the ./install/terraform
folder as the starting point of
the Code Blind submodule, which contains all necessary Terraform configuration files.
Next, make sure that you can authenticate using gcloud:
gcloud auth application-default login
Option 1: Creating the cluster in the default VPC
To create your GKE cluster in the default VPC just specify the project variable.
terraform apply -var project="<YOUR_GCP_ProjectID>"
Option 2: Creating the cluster in a custom VPC
To create the cluster in a custom VPC you must specify the project, network and subnetwork variables.
terraform apply -var project="<YOUR_GCP_ProjectID>" -var network="<YOUR_NETWORK_NAME>" -var subnetwork="<YOUR_SUBNETWORK_NAME>"
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:
You should have 6 nodes in Ready
state.
Uninstall the Code Blind and delete GKE cluster
To delete all resources provisioned by Terraform:
terraform destroy -var project="<YOUR_GCP_ProjectID>"
Next Steps
2 - Installing Code Blind on AWS Elastic Kubernetes Service using Terraform
You can use Terraform to provision an EKS cluster and install Code Blind on it.
Installation
You can use Terraform to provision your Amazon EKS (Elastic Kubernetes Service) cluster and install Code Blind on it using the Helm Terraform provider.
An example of the EKS submodule config file can be found here:
Terraform configuration with Code Blind submodule
Copy this file into a separate folder.
Configure your AWS CLI tool CLI configure:
Initialise your terraform:
Creating Cluster
By editing modules.tf
you can change the parameters that you need to. For instance, the - machine_type
variable.
Configurable parameters:
- cluster_name - the name of the EKS 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 - EC2 instance type for hosting game servers (default is “t2.large”)
- region - the location of the cluster (default is “us-west-2”)
- node_count - count of game server nodes for the default node pool (default is “4”)
- 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”
- gameserver_minPort - the lower bound of the port range which gameservers will listen on (default is “7000”)
- gameserver_maxPort - the upper bound of the port range which gameservers will listen on (default is “8000”)
- gameserver_namespaces - a list of namespaces which will be used to run gameservers (default is
["default"]
). For example ["default", "xbox-gameservers", "mobile-gameservers"]
- force_update - whether or not to force the replacement/update of resource (default is true, false may be required to prevent immutability errors when updating the configuration)
Now you can create an EKS cluster and deploy Code Blind on EKS:
terraform apply [-var agones_version="1.38.0"]
After deploying the cluster with Code Blind, you can get or update your kubeconfig by using:
aws eks --region us-west-2 update-kubeconfig --name agones-cluster
With the following output:
Added new context arn:aws:eks:us-west-2:601646756426:cluster/agones-cluster to /Users/user/.kube/config
Switch kubectl
context to the recently created one:
kubectl config use-context arn:aws:eks:us-west-2:601646756426:cluster/agones-cluster
Check that you are authenticated against the recently created Kubernetes cluster:
Uninstall the Code Blind and delete EKS cluster
Run the following commands to delete all Terraform provisioned resources:
terraform destroy -target module.helm_agones.helm_release.agones -auto-approve && sleep 60
terraform destroy
Note
There is an issue with the AWS Terraform provider:
https://github.com/terraform-providers/terraform-provider-aws/issues/9101
Due to this issue you should remove helm release first (as stated above),
otherwise
terraform destroy
will timeout and never succeed.
Remove all created resources manually in that case, namely: 3 Auto Scaling groups, EKS cluster, and a VPC with all dependent resources.
3 - Installing Code Blind on Azure Kubernetes Service using Terraform
You can use Terraform to provision an AKS cluster and install Code Blind on it.
Installation
Install az
utility by following these instructions.
The example of AKS submodule configuration could be found here:
Terraform configuration with Code Blind submodule
Copy module.tf
file into a separate folder.
Log in to Azure CLI:
Configure your terraform:
Create a service principal and configure its access to Azure resources:
Now you can deploy your cluster (use values from the above command output):
terraform apply -var client_id="<appId>" -var client_secret="<password>"
Once you created all resources on AKS you can get the credentials so that you can use kubectl
to configure your cluster:
az aks get-credentials --resource-group agonesRG --name test-cluster
Check that you have access to the Kubernetes cluster:
Configurable parameters:
- log_level - possible values: Fatal, Error, Warn, Info, Debug (default is “info”)
- cluster_name - the name of the AKS 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 - node machine type for hosting game servers (default is “Standard_D2_v2”)
- disk_size - disk size of the node
- region - the location of the cluster
- node_count - count of game server nodes for the default node pool (default is “4”)
- feature_gates - a list of alpha and beta version features to enable. For example, “PlayerTracking=true&ContainerPortAllocation=true”
- gameserver_minPort - the lower bound of the port range which gameservers will listen on (default is “7000”)
- gameserver_maxPort - the upper bound of the port range which gameservers will listen on (default is “8000”)
- gameserver_namespaces - a list of namespaces which will be used to run gameservers (default is
["default"]
). For example ["default", "xbox-gameservers", "mobile-gameservers"]
- force_update - whether or not to force the replacement/update of resource (default is true, false may be required to prevent immutability errors when updating the configuration)
Uninstall the Code Blind and delete AKS cluster
Run next command to delete all Terraform provisioned resources:
Reference
Details on how you can authenticate your AKS terraform provider using official instructions.
Next Steps