• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple, two player multiplayer game built to show how you can host dedicated game servers on Kubernetes.

Paddle Soccer

A simple, two player multiplayer game built to show how you can host dedicated game servers on Kubernetes.

It has been implemented using Unity for the game client and dedicated game server, and Go for the backend service components that sit on top of Kubernetes.

Screenshot

Overview

Game servers are started up as a Pod on request through the Kubernetes API, and configured to use Host Networking, to avoid any network latency issues through a Load Balancer. The Game Servers start on a random port between a given range (defaults to 2000-3000), and then register themselves against a custom API with their Pod name for later lookup.

Once the game server has started, we use the combination of the Kubernetes API and the aforementioned custom port registry to determine which node in the Kubernetes cluster the Pod has been scheduled on, that node's external IP and what port the game server is open on. This is then pass that back to the game client, through a match maker or otherwise, so that they can connect to it directly.

Blog Posts

Presentations

GCAP Australia
GDC

Unity Structure

The unity source code can be found in the unity folder.

It was built with Unity 5.6.0. It was built on Linux, but the client should run on any OS.

To quickly make the Client and Server builds (for Linux), you can run the Build Pipeline under the Build > Build Game and Server menu

Once the server infrastructure has been configured, you can start the game with a -match command line argument, to tell it where the matchmaker is. For example:

./Game.x86_64 -match "http://10.32.14.10" -logFile /dev/stdout

Server

All the non-Unity server side code is found in the server folder.

Infrastructure

This project works on Kubernetes 1.6.0 or higher, as it uses Kubernetes Node Affinity.

If you have a Google Cloud Platform Project configured and the Google Cloud SDK installed, you can cd into the infrastructure folder, and run make deploy to deploy a 4 node cluster over 2 nodepools, as well as the accompanying firewall rules. make auth will authenticate your local kubectl tooling with this cluster.

Node Pools

  • There are two Node Pools withing this cluster.
    • "apps" (Node Selector role=apps) - which is the area in which Sessons, Matchmaker and Nodescaler all run, so as to keep application separate from the game servers, and not have them impact CPU performance.
    • "game-servers" (Node Selector role=game-servers) - for which game servers will be exclusively run on, and for ease of autoscaling.

Game Server

The game-server folder contains Dockerfile for the Unity dedicated server. To build the server, and the image (on Linux) run make build and then make push to push the image up to Container Registry for use.

Sessions

The sessions folder contains the Go application manages the HTTP API that creates new instances of the Unity Game Server within a Pod. It also hosts the HTTP API the that Game Server connects to to register the port that it currently runs on, with the podname is it provided through an Environment variable.

To build the code for the Docker image and push the image up to the Container Registry, run make build push. To deploy, run make deploy-all and it will deploy the Redis Stateful Set, and the Kubernetes Deployment and accompanying Service.

Matchmaker

The matchmaker folder contains a Go application that is a very simple HTTP based matchmaker that pairs the first two players that request a game in FIFO order. It coordinated with the session manager to start game servers, and inspect what IP and port they are running on, so it can be passed back to the client.

To build the code for the Docker image and push the image up to the Container Registry, run make build push. To deploy, run make deploy-all and it will deploy the Redis Stateful Set, and the Kubernetes Deployment and accompanying Service.

NodeScaler

The nodescaler folder contains a Go application that tracks resource usage within the game-server node pool and increases the number of nodes if the amount of CPU space available falls below a certain buffer value. Once the buffer is exceeded, the node scaler will first cordon nodes that have game servers still running on them, and then eventually delete them once they are empty of running dedicated game servers.

Currently only implemented to work on Google Cloud Platform, through its Container Engine API and Compute Engine Instance Group Manager API, but has been written for extension if required.

To build the code for the Docker image and push the image up to the Container Registry, run make build push. To deploy, run make deploy-all and it will deploy the Kubernetes Deployment for this.

Licence

Apache 2.0

This is not an official Google product.

More Repositories

1

brute

A simple and lightweight Entity Component System library for writing games with Clojure and ClojureScript.
Clojure
181
star
2

JavaLoader

JavaLoader is a library that has been built to ease the use, development and integration of Java within ColdFusion applications.
ColdFusion
58
star
3

wrapping-clojure-tooling-in-containers

Example of a Clojure development environment inside a Docker container
Makefile
50
star
4

ColdDoc

ColdDoc is a tool that has been built to generate documentation based on ColdFusion Component Meta Data.
ColdFusion
44
star
5

happy-angry-surprised

A very silly, web based, Firebase and Cloud Vision API multiplayer game that works exactly the same as Rock, Paper, Scissor - except with facial emotions.
JavaScript
43
star
6

dotfiles

My dotfiles and local machine provisioning
Shell
38
star
7

coldspring

ColdSpring makes the configuration and dependencies of your CFCs easier to manage. ColdSpring brings the power of the popular Spring framework for Java to ColdFusion.
ColdFusion
38
star
8

Sesame

Library of functions to be used with ColdFusion Closures.
ColdFusion
36
star
9

while-let

Repeatedly executes body while test expression is true, evaluating the body with binding-form bound to the value of test.
Clojure
20
star
10

tmux-intellij

Plugin that provides Tmux integration with IntelliJ.
Java
19
star
11

brute-play-pong

A Pong clone written with the Brute Entity Component System library, and Play-CLJ
Clojure
18
star
12

edn-example

Small example of how to take Clojure data structures, and convert them to EDN format, and also read them back again.
Clojure
11
star
13

Squabble

Squabble - ColdFusion Multivariate Testing Suite
JavaScript
9
star
14

psmouse-focaltech-dkms

Attempt to make https://github.com/mgottschlag/linux into a DKMS driver. (May now work)
C
7
star
15

nodejs-docker-and-kubernetes

Simple example of running NodeJS on Kubernetes.
HTML
7
star
16

appengine-golang-gopath

Examples showing options for managing GOPATHs when developing with a Go App Engine projects.
Go
7
star
17

rust-bst

Rust implementation of a binary search tree
Rust
6
star
18

ansible_wordpress

Managing Wordpress with Ansible
Python
6
star
19

jruby-lwjgl

Examples of how to use LWJGL with JRuby
Ruby
5
star
20

recommendation-neo4j

Presentation on a simple item based collaborative filters, using Neo4J
Go
5
star
21

vagrant_ansible_example

Example of setting up Vagrant with Ansible provisioner
Python
4
star
22

closureonclosures

This is the presentation + code of my presentation on Closures in ColdFusion 10
ColdFusion
4
star
23

libgdx-clj-example

Example clojure application with native libgdx integration.
Clojure
2
star
24

Presentation-Coldfusion-Frameworks

The code for the presentation on ColdFusion Frameworks
ColdFusion
2
star
25

guake

Clone of the Guake Terminal Application - http://guake.org/
Python
1
star
26

go-gae-war-stories

Presentation on my experience with Go + GAE
CSS
1
star